@tachybase/module-multi-app 1.5.1 → 1.6.1

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 (94) hide show
  1. package/dist/externalVersion.js +5 -5
  2. package/dist/node_modules/mariadb/callback.js +43 -8
  3. package/dist/node_modules/mariadb/check-node.js +30 -0
  4. package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
  5. package/dist/node_modules/mariadb/lib/cluster.js +446 -0
  6. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
  7. package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
  8. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
  9. package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
  10. package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
  11. package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
  12. package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
  13. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
  14. package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
  15. package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
  16. package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
  17. package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
  18. package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
  19. package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
  20. package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
  21. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
  22. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
  23. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
  24. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
  25. package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
  26. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
  27. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
  28. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
  29. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
  30. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
  34. package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
  35. package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
  36. package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
  37. package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
  38. package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
  39. package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
  40. package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
  41. package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
  42. package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
  43. package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
  44. package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
  45. package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
  46. package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
  47. package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
  48. package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
  49. package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
  50. package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
  51. package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
  52. package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
  53. package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
  54. package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
  55. package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
  56. package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
  57. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
  58. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
  59. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
  60. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
  61. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
  62. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
  63. package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
  64. package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
  65. package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
  66. package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
  67. package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
  68. package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
  69. package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
  70. package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
  71. package/dist/node_modules/mariadb/lib/pool.js +951 -0
  72. package/dist/node_modules/mariadb/package.json +1 -1
  73. package/dist/node_modules/mariadb/promise.js +1 -34
  74. package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
  75. package/dist/node_modules/mariadb/types/index.d.ts +94 -674
  76. package/dist/node_modules/mariadb/types/share.d.ts +804 -0
  77. package/dist/node_modules/qs/package.json +1 -1
  78. package/dist/server/actions/apps.js +2 -2
  79. package/dist/server/app-lifecycle.d.ts +1 -1
  80. package/dist/server/app-lifecycle.js +4 -4
  81. package/dist/server/models/application.d.ts +1 -1
  82. package/package.json +7 -7
  83. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  84. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  85. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  86. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  87. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  88. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  89. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  90. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  91. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  92. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  93. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  94. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
@@ -1,590 +0,0 @@
1
- 'use strict';
2
-
3
- const moment = require('moment-timezone');
4
- const Iconv = require('iconv-lite');
5
- const SMALL_BUFFER_SIZE = 1024;
6
- const MEDIUM_BUFFER_SIZE = 16384; //16k
7
- const LARGE_BUFFER_SIZE = 131072; //128k
8
- const BIG_BUFFER_SIZE = 1048576; //1M
9
- const MAX_BUFFER_SIZE = 16777219; //16M + 4
10
-
11
- /**
12
- * Packet splitter.
13
- *
14
- * The servers have a limit max_allowed_packet which limits the size of the data sent, to avoid saturating the server in memory.
15
- *
16
- * The following implementation has a workaround that will rewrite the command and separate the send according to this value.
17
- * This implies that this command can send multiple commands, with some tricks for sequencing packets.
18
- *
19
- */
20
- class BulkPacket {
21
- constructor(opts, out, row) {
22
- this.out = out;
23
- this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
24
- this.pos = 4;
25
- this.datatypes = [];
26
- this.encoding = out.encoding;
27
- this.statementId = -1;
28
- this.waitingResponseNo = 1;
29
- this.singleQuery = false;
30
- this.haveErrorResponse = false;
31
- this.writeBinaryDate = opts.tz
32
- ? opts.tz === 'Etc/UTC'
33
- ? this.writeBinaryUtcDate
34
- : this.writeBinaryTimezoneDate
35
- : this.writeBinaryLocalDate;
36
- if (this.encoding === 'utf8') {
37
- this.writeLengthEncodedString = this.writeDefaultLengthEncodedString;
38
- } else if (Buffer.isEncoding(this.encoding)) {
39
- this.writeLengthEncodedString = this.writeDefaultLengthEncodedString;
40
- } else {
41
- this.writeLengthEncodedString = this.writeIconvLengthEncodedString;
42
- }
43
- this.maxAllowedPacket = opts.maxAllowedPacket;
44
- this.maxPacketSize = opts.maxAllowedPacket
45
- ? Math.min(MAX_BUFFER_SIZE, opts.maxAllowedPacket)
46
- : 4194304;
47
- this.writeHeader(row);
48
- }
49
-
50
- datatypeChanged(row) {
51
- if (this.datatypes.length !== row.length) return true;
52
- for (let r = 0; r < row.length; r++) {
53
- if (row[r] !== null) {
54
- switch (typeof row[r]) {
55
- case 'boolean':
56
- if (this.datatypes[r] !== 0x01) return true;
57
- break;
58
- case 'number':
59
- case 'bigint':
60
- if (this.datatypes[r] !== 0x0f) return true;
61
- break;
62
- case 'object':
63
- if (Object.prototype.toString.call(row[r]) === '[object Date]') {
64
- if (this.datatypes[r] !== 0x0c) return true;
65
- } else if (Buffer.isBuffer(row[r])) {
66
- if (this.datatypes[r] !== 0xfb) return true;
67
- } else if (
68
- row[r].type != null &&
69
- [
70
- 'Point',
71
- 'LineString',
72
- 'Polygon',
73
- 'MultiPoint',
74
- 'MultiLineString',
75
- 'MultiPolygon',
76
- 'GeometryCollection'
77
- ].includes(row[r].type)
78
- ) {
79
- if (this.datatypes[r] !== 0xfb) return true;
80
- } else {
81
- if (this.datatypes[r] !== 0x0f) return true;
82
- }
83
- break;
84
- default:
85
- if (this.datatypes[r] !== 0x0f) return true;
86
- }
87
- }
88
- }
89
- return false;
90
- }
91
-
92
- writeHeader(row) {
93
- this.buf[this.pos++] = 0xfa;
94
-
95
- //use last prepare command
96
- this.buf[this.pos++] = this.statementId;
97
- this.buf[this.pos++] = this.statementId >> 8;
98
- this.buf[this.pos++] = this.statementId >> 16;
99
- this.buf[this.pos++] = this.statementId >> 24;
100
- //set bulk flags to Send types to server
101
- this.buf[this.pos++] = 0x80;
102
- this.buf[this.pos++] = 0x00;
103
-
104
- //send data type (strings)
105
- this.datatypes = [];
106
- if (row) {
107
- for (let r = 0; r < row.length; r++) {
108
- if (row[r] === null) {
109
- this.buf[this.pos++] = 0x0f;
110
- } else {
111
- switch (typeof row[r]) {
112
- case 'boolean':
113
- this.buf[this.pos++] = 0x01;
114
- break;
115
- case 'bigint':
116
- case 'number':
117
- this.buf[this.pos++] = 0x0f;
118
- break;
119
- case 'object':
120
- if (Object.prototype.toString.call(row[r]) === '[object Date]') {
121
- this.buf[this.pos++] = 0x0c;
122
- } else if (Buffer.isBuffer(row[r])) {
123
- this.buf[this.pos++] = 0xfb;
124
- } else if (
125
- row[r].type != null &&
126
- [
127
- 'Point',
128
- 'LineString',
129
- 'Polygon',
130
- 'MultiPoint',
131
- 'MultiLineString',
132
- 'MultiPolygon',
133
- 'GeometryCollection'
134
- ].includes(row[r].type)
135
- ) {
136
- this.buf[this.pos++] = 0xfb;
137
- } else {
138
- this.buf[this.pos++] = 0x0f;
139
- }
140
- break;
141
- default:
142
- this.buf[this.pos++] = 0x0f;
143
- }
144
- }
145
- this.datatypes[r] = this.buf[this.pos - 1];
146
- this.buf[this.pos++] = 0x00;
147
- }
148
- }
149
- }
150
-
151
- growBuffer(len) {
152
- let newCapacity;
153
- if (len + this.pos < MEDIUM_BUFFER_SIZE) {
154
- newCapacity = MEDIUM_BUFFER_SIZE;
155
- } else if (len + this.pos < LARGE_BUFFER_SIZE) {
156
- newCapacity = LARGE_BUFFER_SIZE;
157
- } else if (len + this.pos < BIG_BUFFER_SIZE) {
158
- newCapacity = BIG_BUFFER_SIZE;
159
- } else newCapacity = MAX_BUFFER_SIZE;
160
-
161
- if (newCapacity > this.maxPacketSize && this.markPos) {
162
- this.flush(false, len);
163
- return true;
164
- } else {
165
- let newBuf = Buffer.allocUnsafe(Math.min(newCapacity));
166
- this.buf.copy(newBuf, 0, 0, this.pos);
167
- this.buf = newBuf;
168
- return false;
169
- }
170
- }
171
-
172
- writeLengthStringAscii(val) {
173
- let len = val.length;
174
- //not enough space remaining
175
- if (len >= this.buf.length - this.pos) {
176
- let strBuf = Buffer.from(val, 'ascii');
177
- return this.writeLengthEncodedBuffer(strBuf);
178
- }
179
-
180
- this.writeLength(len);
181
- for (let off = 0; off < len; ) {
182
- this.buf[this.pos++] = val.charCodeAt(off++);
183
- }
184
- return false;
185
- }
186
-
187
- writeLength(len) {
188
- if (len < 0xfb) {
189
- return this.writeInt8(len);
190
- } else if (len < 65536) {
191
- let flushed = this.writeInt8(0xfc);
192
- return this.writeInt16(len) || flushed;
193
- } else if (len < 16777216) {
194
- let flushed = this.writeInt8(0xfd);
195
- return this.writeInt24(len) || flushed;
196
- } else {
197
- //4 last bytes are filled with 0, packet limitation size is 32 bit integer
198
- if (this.pos + 9 >= this.buf.length) {
199
- const tmpBuf = Buffer.allocUnsafe(9);
200
- tmpBuf[0] = 0xfe;
201
- tmpBuf[1] = len;
202
- tmpBuf[2] = len >>> 8;
203
- tmpBuf[3] = len >>> 16;
204
- tmpBuf[4] = len >>> 24;
205
- tmpBuf[5] = 0;
206
- tmpBuf[6] = 0;
207
- tmpBuf[7] = 0;
208
- tmpBuf[8] = 0;
209
- return this.writeBuffer(tmpBuf);
210
- }
211
- this.buf[this.pos++] = 0xfe;
212
- this.buf[this.pos++] = len;
213
- this.buf[this.pos++] = len >>> 8;
214
- this.buf[this.pos++] = len >>> 16;
215
- this.buf[this.pos++] = len >>> 24;
216
- this.buf[this.pos++] = 0;
217
- this.buf[this.pos++] = 0;
218
- this.buf[this.pos++] = 0;
219
- this.buf[this.pos++] = 0;
220
- return false;
221
- }
222
- }
223
-
224
- writeLengthEncodedBuffer(val) {
225
- let valLen = val.length;
226
- let flushed = this.writeLength(valLen);
227
- return this.writeBuffer(val) || flushed;
228
- }
229
-
230
- writeBuffer(val) {
231
- let flushed = false;
232
- let valLen = val.length;
233
- if (valLen > this.buf.length - this.pos) {
234
- //makes buffer bigger (up to 16M)
235
- if (this.buf.length < MAX_BUFFER_SIZE) flushed = this.growBuffer(valLen * 2);
236
-
237
- //data may still be bigger than buffer.
238
- //must flush buffer when full (and reset position to 4)
239
- if (valLen > this.buf.length - this.pos) {
240
- let tmpPos = this.buf.length - this.pos;
241
- val.copy(this.buf, this.pos, 0, tmpPos);
242
- this.pos += tmpPos;
243
- this.flush(false, valLen - tmpPos);
244
-
245
- while (tmpPos < valLen) {
246
- if (this.buf.length - this.pos < valLen - tmpPos) this.growBuffer(valLen - tmpPos);
247
- const toWrite = Math.min(valLen - tmpPos, this.buf.length - this.pos);
248
- val.copy(this.buf, this.pos, tmpPos, tmpPos + toWrite);
249
- tmpPos += toWrite;
250
- this.pos += toWrite;
251
- if (valLen - tmpPos > 0) this.flush(false, valLen - tmpPos);
252
- }
253
- return true;
254
- }
255
- }
256
-
257
- //sure to have enough place to use buffer directly
258
- val.copy(this.buf, this.pos, 0, valLen);
259
- this.pos += valLen;
260
- return flushed;
261
- }
262
-
263
- writeInt8(value) {
264
- let flushed = false;
265
- if (this.pos + 1 > this.buf.length) {
266
- if (this.buf.length < MAX_BUFFER_SIZE) {
267
- flushed = this.growBuffer(1);
268
- } else {
269
- this.flush(false, 1);
270
- this.buf[this.pos++] = value;
271
- return true;
272
- }
273
- }
274
- this.buf[this.pos++] = value;
275
- return flushed;
276
- }
277
-
278
- writeInt16(value) {
279
- let flushed = false;
280
- if (this.pos + 2 > this.buf.length) {
281
- if (this.buf.length < this.maxPacketSize) flushed = this.growBuffer(2);
282
- if (this.pos + 2 > this.buf.length) {
283
- const tmpBuf = Buffer.allocUnsafe(2);
284
- tmpBuf[0] = value;
285
- tmpBuf[1] = value >>> 8;
286
- this.writeBuffer(tmpBuf);
287
- return true;
288
- }
289
- }
290
- this.buf[this.pos++] = value;
291
- this.buf[this.pos++] = value >>> 8;
292
- return flushed;
293
- }
294
-
295
- writeInt24(value) {
296
- let flushed = false;
297
- if (this.pos + 3 > this.buf.length) {
298
- if (this.buf.length < this.maxPacketSize) flushed = this.growBuffer(3);
299
- if (this.pos + 3 > this.buf.length) {
300
- const tmpBuf = Buffer.allocUnsafe(3);
301
- tmpBuf[0] = value;
302
- tmpBuf[1] = value >>> 8;
303
- tmpBuf[2] = value >>> 16;
304
- this.writeBuffer(tmpBuf);
305
- return true;
306
- }
307
- }
308
- this.buf[this.pos++] = value;
309
- this.buf[this.pos++] = value >>> 8;
310
- this.buf[this.pos++] = value >>> 16;
311
- return flushed;
312
- }
313
-
314
- writeIconvLengthEncodedString(str) {
315
- let buf = Iconv.encode(str, this.encoding);
316
- return this.writeLengthEncodedBuffer(buf, 0, buf.length);
317
- }
318
-
319
- writeDefaultLengthEncodedString(str) {
320
- //javascript use UCS-2 or UTF-16 string internal representation
321
- //that means that string to byte will be a maximum of * 3
322
- // (4 bytes utf-8 are represented on 2 UTF-16 characters)
323
- if (str.length * 3 + 10 < this.buf.length - this.pos) {
324
- //reserve position for length indicator
325
- const maxLen = str.length * 3;
326
- let lengthPos;
327
- if (maxLen < 0xfb) {
328
- lengthPos = this.pos;
329
- this.pos++;
330
- } else if (maxLen < 65536) {
331
- this.buf[this.pos++] = 0xfc;
332
- lengthPos = this.pos;
333
- this.pos += 2;
334
- } else {
335
- //if len was > 16M, would have been > to buffer length
336
- this.buf[this.pos++] = 0xfd;
337
- lengthPos = this.pos;
338
- this.pos += 3;
339
- }
340
- const prevPos = this.pos;
341
- this.pos += this.buf.write(str, this.pos, this.encoding);
342
- //write real data length
343
- const realLen = this.pos - prevPos;
344
- if (maxLen < 0xfb) {
345
- this.buf[lengthPos] = realLen;
346
- } else if (maxLen < 65536) {
347
- this.buf[lengthPos] = realLen;
348
- this.buf[lengthPos + 1] = realLen >>> 8;
349
- } else {
350
- this.buf[lengthPos] = realLen;
351
- this.buf[lengthPos + 1] = realLen >>> 8;
352
- this.buf[lengthPos + 2] = realLen >>> 16;
353
- }
354
- return false;
355
- }
356
-
357
- //checking real length
358
- let flushed = false;
359
- let byteLength = Buffer.byteLength(str, this.encoding);
360
- if (byteLength + 9 > this.buf.length - this.pos) {
361
- if (this.buf.length < MAX_BUFFER_SIZE) flushed = this.growBuffer(byteLength + 9);
362
-
363
- if (byteLength > this.buf.length - this.pos) {
364
- //not enough space in buffer, will stream :
365
- let strBuf = Buffer.from(str, this.encoding);
366
- return this.writeLengthEncodedBuffer(strBuf) || flushed;
367
- }
368
- }
369
- this.writeLength(byteLength);
370
- this.pos += this.buf.write(str, this.pos, this.encoding);
371
- return flushed;
372
- }
373
-
374
- writeBinaryLocalDate(date, opts) {
375
- const year = date.getFullYear();
376
- const mon = date.getMonth() + 1;
377
- const day = date.getDate();
378
- const hour = date.getHours();
379
- const min = date.getMinutes();
380
- const sec = date.getSeconds();
381
- const ms = date.getMilliseconds();
382
- return this._writeBinaryDate(year, mon, day, hour, min, sec, ms);
383
- }
384
-
385
- writeBinaryUtcDate(date, opts) {
386
- const year = date.getUTCFullYear();
387
- const mon = date.getUTCMonth() + 1;
388
- const day = date.getUTCDate();
389
- const hour = date.getUTCHours();
390
- const min = date.getUTCMinutes();
391
- const sec = date.getUTCSeconds();
392
- const ms = date.getUTCMilliseconds();
393
- return this._writeBinaryDate(year, mon, day, hour, min, sec, ms);
394
- }
395
-
396
- _writeBinaryDate(year, mon, day, hour, min, sec, ms) {
397
- let len = ms === 0 ? 7 : 11;
398
- //not enough space remaining
399
- if (len + 1 > this.buf.length - this.pos) {
400
- let tmpBuf = Buffer.allocUnsafe(len + 1);
401
-
402
- tmpBuf[0] = len;
403
- tmpBuf[1] = year;
404
- tmpBuf[2] = year >>> 8;
405
- tmpBuf[3] = mon;
406
- tmpBuf[4] = day;
407
- tmpBuf[5] = hour;
408
- tmpBuf[6] = min;
409
- tmpBuf[7] = sec;
410
- if (ms !== 0) {
411
- const micro = ms * 1000;
412
- tmpBuf[8] = micro;
413
- tmpBuf[9] = micro >>> 8;
414
- tmpBuf[10] = micro >>> 16;
415
- tmpBuf[11] = micro >>> 24;
416
- }
417
-
418
- return this.writeBuffer(tmpBuf);
419
- }
420
-
421
- this.buf[this.pos] = len;
422
- this.buf[this.pos + 1] = year;
423
- this.buf[this.pos + 2] = year >>> 8;
424
- this.buf[this.pos + 3] = mon;
425
- this.buf[this.pos + 4] = day;
426
- this.buf[this.pos + 5] = hour;
427
- this.buf[this.pos + 6] = min;
428
- this.buf[this.pos + 7] = sec;
429
-
430
- if (ms !== 0) {
431
- const micro = ms * 1000;
432
- this.buf[this.pos + 8] = micro;
433
- this.buf[this.pos + 9] = micro >>> 8;
434
- this.buf[this.pos + 10] = micro >>> 16;
435
- this.buf[this.pos + 11] = micro >>> 24;
436
- }
437
- this.pos += len + 1;
438
- return false;
439
- }
440
-
441
- writeBinaryTimezoneDate(date, opts) {
442
- const dateZoned = new Date(
443
- moment.tz(date, opts._localTz).tz(opts.tz).format('YYYY-MM-DD HH:mm:ss.SSSSSS')
444
- );
445
- const year = dateZoned.getFullYear();
446
- const mon = dateZoned.getMonth() + 1;
447
- const day = dateZoned.getDate();
448
- const hour = dateZoned.getHours();
449
- const min = dateZoned.getMinutes();
450
- const sec = dateZoned.getSeconds();
451
- const ms = dateZoned.getMilliseconds();
452
- return this._writeBinaryDate(year, mon, day, hour, min, sec, ms);
453
- }
454
-
455
- mark(isLast, nextRow) {
456
- let flushed = false;
457
- this.nextRow = nextRow;
458
- if (this.singleQuery) {
459
- //end of big query that is more than 16M
460
- //write single one
461
- if (!this.haveErrorResponse) {
462
- const packetSendSize =
463
- this.pos +
464
- (this.singleQuerySequenceNo !== undefined
465
- ? (this.singleQuerySequenceNo + 1) * MAX_BUFFER_SIZE
466
- : 0);
467
- if (this.maxAllowedPacket && packetSendSize > this.maxAllowedPacket) {
468
- console.log(
469
- "will send a packet to db server with size > connection option 'maxAllowedPacket' (size send is " +
470
- packetSendSize +
471
- ') connection might be reset by server'
472
- );
473
- }
474
- this.copyAndFlush(true);
475
- flushed = true;
476
- this.markPos = undefined;
477
- }
478
-
479
- this.singleQuerySequenceNo = undefined;
480
- this.singleQueryCompressSequenceNo = undefined;
481
- this.singleQuery = false;
482
- this.writeHeader(nextRow);
483
- this.markPos = undefined;
484
- } else {
485
- if (!isLast && this.datatypeChanged(nextRow)) {
486
- this.markPos = this.pos;
487
- this.flushMark();
488
- flushed = true;
489
- } else if (this.markPos && this.pos > this.maxPacketSize) {
490
- //not enough room for current query , flush mark.
491
- this.flushMark();
492
- flushed = true;
493
- } else {
494
- //just mark ending query
495
- this.markPos = this.pos;
496
- if (isLast) {
497
- this.flushMark();
498
- flushed = true;
499
- }
500
- }
501
- }
502
- return flushed;
503
- }
504
-
505
- flush(end, remainingLen) {
506
- if (this.markPos && !this.singleQuery) {
507
- this.flushMark();
508
- } else {
509
- //one insert is more than 16M, will continue to mono insert, hoping
510
- //that max_allowed_packet is sized accordingly to query.
511
- if (this.buf.length < MAX_BUFFER_SIZE) {
512
- //in this case, connector has default to 4M packet, and a single query size
513
- //is > to 4mb. growing buffer to 16M
514
- let newBuf = Buffer.allocUnsafe(MAX_BUFFER_SIZE);
515
- this.buf.copy(newBuf, 0, 0, this.pos);
516
- this.buf = newBuf;
517
- } else {
518
- if (!this.haveErrorResponse) {
519
- if (this.maxAllowedPacket && this.buf.length > this.maxAllowedPacket) {
520
- console.log(
521
- "will send a packet to server with size > connection option 'maxAllowedPacket' (size send is " +
522
- this.pos +
523
- ') connection might be reset by server'
524
- );
525
- }
526
- this.copyAndFlush(false);
527
-
528
- this.markPos = undefined;
529
- if (!this.singleQuery) this.waitingResponseNo++;
530
- this.singleQuery = true;
531
- this.singleQuerySequenceNo = this.out.cmd.sequenceNo;
532
- this.singleQueryCompressSequenceNo = this.out.cmd.compressSequenceNo;
533
- }
534
- }
535
- }
536
- }
537
-
538
- flushMark() {
539
- let afterMark;
540
- if (this.pos !== this.markPos) {
541
- afterMark = Buffer.allocUnsafe(this.pos - this.markPos);
542
- this.buf.copy(afterMark, 0, this.markPos, this.pos);
543
- }
544
-
545
- this.pos = this.markPos;
546
-
547
- if (!this.haveErrorResponse) {
548
- this.copyAndFlush(true);
549
- this.waitingResponseNo++;
550
- }
551
-
552
- this.pos = 4;
553
- this.markPos = undefined;
554
- if (this.nextRow) this.writeHeader(this.nextRow);
555
- if (afterMark) {
556
- if (this.buf.length - this.pos < afterMark.length)
557
- this.growBuffer(afterMark.length - (this.buf.length - this.pos));
558
- afterMark.copy(this.buf, this.pos, 0, afterMark.length);
559
- this.pos += afterMark.length;
560
- }
561
- this.singleQuery = false;
562
- this.singleQuerySequenceNo = undefined;
563
- this.singleQueryCompressSequenceNo = undefined;
564
- }
565
-
566
- copyAndFlush(ended) {
567
- this.out.buf = this.buf;
568
- this.out.pos = this.pos;
569
- if (this.singleQuerySequenceNo !== undefined) {
570
- this.out.cmd.sequenceNo = this.singleQuerySequenceNo;
571
- this.out.cmd.compressSequenceNo = this.singleQueryCompressSequenceNo;
572
- } else {
573
- this.out.cmd.sequenceNo = -1;
574
- this.out.cmd.compressSequenceNo = -1;
575
- }
576
- this.out.flushBuffer(ended);
577
- if (this.singleQuerySequenceNo !== undefined) {
578
- this.singleQuerySequenceNo = this.out.cmd.sequenceNo;
579
- this.singleQueryCompressSequenceNo = this.out.cmd.compressSequenceNo;
580
- }
581
- this.pos = 4;
582
- this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
583
- }
584
-
585
- endedWithError() {
586
- this.haveErrorResponse = true;
587
- }
588
- }
589
-
590
- module.exports = BulkPacket;