@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.
- package/README.md +34 -34
- package/README.zh-CN.md +34 -34
- package/client.d.ts +1 -1
- package/client.js +1 -1
- package/dist/externalVersion.js +5 -5
- package/dist/locale/en-US.json +48 -48
- package/dist/locale/es-ES.json +9 -9
- package/dist/locale/ko_KR.json +11 -11
- package/dist/locale/pt-BR.json +9 -9
- package/dist/locale/zh-CN.json +58 -58
- package/dist/node_modules/mariadb/callback.js +43 -8
- package/dist/node_modules/mariadb/check-node.js +30 -0
- package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
- package/dist/node_modules/mariadb/lib/cluster.js +446 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
- package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
- package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
- package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
- package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
- package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
- package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
- package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
- package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
- package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
- package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
- package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
- package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
- package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
- package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
- package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
- package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
- package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
- package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
- package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
- package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
- package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
- package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
- package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
- package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
- package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
- package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
- package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
- package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
- package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
- package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
- package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
- package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
- package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
- package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
- package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
- package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
- package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
- package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
- package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
- package/dist/node_modules/mariadb/lib/pool.js +951 -0
- package/dist/node_modules/mariadb/package.json +1 -1
- package/dist/node_modules/mariadb/promise.js +1 -34
- package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
- package/dist/node_modules/mariadb/types/index.d.ts +94 -674
- package/dist/node_modules/mariadb/types/share.d.ts +804 -0
- package/dist/node_modules/qs/package.json +1 -1
- package/dist/server/actions/apps.js +2 -2
- package/dist/server/app-lifecycle.d.ts +1 -1
- package/dist/server/app-lifecycle.js +4 -4
- package/dist/server/models/application.d.ts +1 -1
- package/package.json +7 -7
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
- package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
- package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Iconv = require('iconv-lite');
|
|
4
|
-
|
|
5
|
-
const QUOTE = 0x27;
|
|
6
|
-
const DBL_QUOTE = 0x22;
|
|
7
|
-
const ZERO_BYTE = 0x00;
|
|
8
|
-
const SLASH = 0x5c;
|
|
9
|
-
|
|
10
|
-
const SMALL_BUFFER_SIZE = 1024;
|
|
11
|
-
const MEDIUM_BUFFER_SIZE = 16384; //16k
|
|
12
|
-
const LARGE_BUFFER_SIZE = 131072; //128k
|
|
13
|
-
const BIG_BUFFER_SIZE = 1048576; //1M
|
|
14
|
-
const MAX_BUFFER_SIZE = 16777219; //16M + 4
|
|
15
|
-
|
|
16
|
-
const CHARS_GLOBAL_REGEXP = /[\0\"\'\\]/g; // eslint-disable-line no-control-regex
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Packet splitter.
|
|
20
|
-
*
|
|
21
|
-
* The servers have a limit max_allowed_packet which limits the size of the data sent, to avoid saturating the server in memory.
|
|
22
|
-
*
|
|
23
|
-
* The following implementation has a workaround that will rewrite the command and separate the send according to this value.
|
|
24
|
-
* This implies that this command can send multiple commands, with some tricks for sequencing packets.
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
class ReWritePacket {
|
|
28
|
-
constructor(maxAllowedPacket, out, initString, endString) {
|
|
29
|
-
this.out = out;
|
|
30
|
-
this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
|
|
31
|
-
this.pos = 4;
|
|
32
|
-
this.initStr = initString;
|
|
33
|
-
this.endStr = endString;
|
|
34
|
-
this.encoding = out.encoding;
|
|
35
|
-
this.endStrLength = Buffer.byteLength(this.endStr, this.encoding);
|
|
36
|
-
this.waitingResponseNo = 0;
|
|
37
|
-
this.singleQuery = false;
|
|
38
|
-
this.haveErrorResponse = false;
|
|
39
|
-
|
|
40
|
-
if (this.encoding === 'utf8') {
|
|
41
|
-
this.writeString = this.writeDefaultBufferString;
|
|
42
|
-
this.writeStringEscapeQuote = this.writeUtf8StringEscapeQuote;
|
|
43
|
-
} else if (Buffer.isEncoding(this.encoding)) {
|
|
44
|
-
this.writeString = this.writeDefaultBufferString;
|
|
45
|
-
this.writeStringEscapeQuote = this.writeDefaultStringEscapeQuote;
|
|
46
|
-
} else {
|
|
47
|
-
this.writeString = this.writeDefaultIconvString;
|
|
48
|
-
this.writeStringEscapeQuote = this.writeDefaultStringEscapeQuote;
|
|
49
|
-
}
|
|
50
|
-
this.maxAllowedPacket = maxAllowedPacket;
|
|
51
|
-
if (maxAllowedPacket) {
|
|
52
|
-
this.maxPacketSize = Math.min(MAX_BUFFER_SIZE, maxAllowedPacket) - this.endStrLength;
|
|
53
|
-
} else this.maxPacketSize = 4194304 - this.endStrLength;
|
|
54
|
-
|
|
55
|
-
this.buf[this.pos++] = 0x03;
|
|
56
|
-
this.writeString(this.initStr);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
growBuffer(len) {
|
|
60
|
-
let newCapacity;
|
|
61
|
-
if (len + this.pos < MEDIUM_BUFFER_SIZE) {
|
|
62
|
-
newCapacity = MEDIUM_BUFFER_SIZE;
|
|
63
|
-
} else if (len + this.pos < LARGE_BUFFER_SIZE) {
|
|
64
|
-
newCapacity = LARGE_BUFFER_SIZE;
|
|
65
|
-
} else if (len + this.pos < BIG_BUFFER_SIZE) {
|
|
66
|
-
newCapacity = BIG_BUFFER_SIZE;
|
|
67
|
-
} else newCapacity = MAX_BUFFER_SIZE;
|
|
68
|
-
|
|
69
|
-
if (newCapacity > this.maxPacketSize && this.markPos) {
|
|
70
|
-
this.flush(false, len);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
let newBuf = Buffer.allocUnsafe(Math.min(newCapacity));
|
|
74
|
-
this.buf.copy(newBuf, 0, 0, this.pos);
|
|
75
|
-
this.buf = newBuf;
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
writeInt8(value) {
|
|
80
|
-
let flushed = false;
|
|
81
|
-
if (this.pos + 1 + this.endStrLength >= this.buf.length) {
|
|
82
|
-
if (this.buf.length < MAX_BUFFER_SIZE) {
|
|
83
|
-
flushed = this.growBuffer(1);
|
|
84
|
-
} else {
|
|
85
|
-
this.flush(false, 1);
|
|
86
|
-
this.buf[this.pos++] = value;
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
this.buf[this.pos++] = value;
|
|
91
|
-
return flushed;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Write ascii string to socket (no escaping)
|
|
96
|
-
*
|
|
97
|
-
* @param str string
|
|
98
|
-
*/
|
|
99
|
-
writeStringAscii(str) {
|
|
100
|
-
let len = str.length;
|
|
101
|
-
|
|
102
|
-
//not enough space remaining
|
|
103
|
-
if (len >= this.buf.length - (this.pos + this.endStrLength)) {
|
|
104
|
-
let strBuf = Buffer.from(str, 'ascii');
|
|
105
|
-
return this.writeBuffer(strBuf, 0, strBuf.length);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
for (let off = 0; off < len; ) {
|
|
109
|
-
this.buf[this.pos++] = str.charCodeAt(off++);
|
|
110
|
-
}
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
writeUtf8StringEscapeQuote(str) {
|
|
115
|
-
const charsLength = str.length;
|
|
116
|
-
|
|
117
|
-
//not enough space remaining
|
|
118
|
-
if (charsLength * 3 + 2 >= this.buf.length - (this.pos + this.endStrLength)) {
|
|
119
|
-
let flushed;
|
|
120
|
-
const arr = Buffer.from(str, 'utf8');
|
|
121
|
-
flushed = this.writeInt8(QUOTE);
|
|
122
|
-
flushed = this.writeBufferEscape(arr) || flushed;
|
|
123
|
-
flushed = this.writeInt8(QUOTE) || flushed;
|
|
124
|
-
return flushed;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
//create UTF-8 byte array
|
|
128
|
-
//since javascript char are internally using UTF-16 using surrogate's pattern, 4 bytes unicode characters will
|
|
129
|
-
//represent 2 characters : example "\uD83C\uDFA4" = 🎤 unicode 8 "no microphones"
|
|
130
|
-
//so max size is 3 * charLength
|
|
131
|
-
//(escape characters are 1 byte encoded, so length might only be 2 when escaped)
|
|
132
|
-
// + 2 for the quotes for text protocol
|
|
133
|
-
let charsOffset = 0;
|
|
134
|
-
let currChar;
|
|
135
|
-
this.buf[this.pos++] = QUOTE;
|
|
136
|
-
//quick loop if only ASCII chars for faster escape
|
|
137
|
-
for (
|
|
138
|
-
;
|
|
139
|
-
charsOffset < charsLength && (currChar = str.charCodeAt(charsOffset)) < 0x80;
|
|
140
|
-
charsOffset++
|
|
141
|
-
) {
|
|
142
|
-
if (
|
|
143
|
-
currChar === SLASH ||
|
|
144
|
-
currChar === QUOTE ||
|
|
145
|
-
currChar === ZERO_BYTE ||
|
|
146
|
-
currChar === DBL_QUOTE
|
|
147
|
-
) {
|
|
148
|
-
this.buf[this.pos++] = SLASH;
|
|
149
|
-
}
|
|
150
|
-
this.buf[this.pos++] = currChar;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
//if quick loop not finished
|
|
154
|
-
while (charsOffset < charsLength) {
|
|
155
|
-
currChar = str.charCodeAt(charsOffset++);
|
|
156
|
-
if (currChar < 0x80) {
|
|
157
|
-
if (
|
|
158
|
-
currChar === SLASH ||
|
|
159
|
-
currChar === QUOTE ||
|
|
160
|
-
currChar === ZERO_BYTE ||
|
|
161
|
-
currChar === DBL_QUOTE
|
|
162
|
-
) {
|
|
163
|
-
this.buf[this.pos++] = SLASH;
|
|
164
|
-
}
|
|
165
|
-
this.buf[this.pos++] = currChar;
|
|
166
|
-
} else if (currChar < 0x800) {
|
|
167
|
-
this.buf[this.pos++] = 0xc0 | (currChar >> 6);
|
|
168
|
-
this.buf[this.pos++] = 0x80 | (currChar & 0x3f);
|
|
169
|
-
} else if (currChar >= 0xd800 && currChar < 0xe000) {
|
|
170
|
-
//reserved for surrogate - see https://en.wikipedia.org/wiki/UTF-16
|
|
171
|
-
if (currChar < 0xdc00) {
|
|
172
|
-
//is high surrogate
|
|
173
|
-
if (charsOffset + 1 > charsLength) {
|
|
174
|
-
this.buf[this.pos++] = 0x3f;
|
|
175
|
-
} else {
|
|
176
|
-
const nextChar = str.charCodeAt(charsOffset);
|
|
177
|
-
if (nextChar >= 0xdc00 && nextChar < 0xe000) {
|
|
178
|
-
//is low surrogate
|
|
179
|
-
const surrogatePairs =
|
|
180
|
-
(currChar << 10) + nextChar + (0x010000 - (0xd800 << 10) - 0xdc00);
|
|
181
|
-
this.buf[this.pos++] = 0xf0 | (surrogatePairs >> 18);
|
|
182
|
-
this.buf[this.pos++] = 0x80 | ((surrogatePairs >> 12) & 0x3f);
|
|
183
|
-
this.buf[this.pos++] = 0x80 | ((surrogatePairs >> 6) & 0x3f);
|
|
184
|
-
this.buf[this.pos++] = 0x80 | (surrogatePairs & 0x3f);
|
|
185
|
-
charsOffset++;
|
|
186
|
-
} else {
|
|
187
|
-
//must have low surrogate
|
|
188
|
-
this.buf[this.pos++] = 0x3f;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
//low surrogate without high surrogate before
|
|
193
|
-
this.buf[this.pos++] = 0x3f;
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
this.buf[this.pos++] = 0xe0 | (currChar >> 12);
|
|
197
|
-
this.buf[this.pos++] = 0x80 | ((currChar >> 6) & 0x3f);
|
|
198
|
-
this.buf[this.pos++] = 0x80 | (currChar & 0x3f);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
this.buf[this.pos++] = QUOTE;
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
writeDefaultIconvString(str) {
|
|
206
|
-
let buf = Iconv.encode(str, this.encoding);
|
|
207
|
-
return this.writeBuffer(buf, 0, buf.length);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
writeDefaultBufferString(str) {
|
|
211
|
-
//javascript use UCS-2 or UTF-16 string internal representation
|
|
212
|
-
//that means that string to byte will be a maximum of * 3
|
|
213
|
-
// (4 bytes utf-8 are represented on 2 UTF-16 characters)
|
|
214
|
-
if (str.length * 3 < this.buf.length - (this.pos + this.endStrLength)) {
|
|
215
|
-
this.pos += this.buf.write(str, this.pos, this.encoding);
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
//checking real length
|
|
220
|
-
let flushed = false;
|
|
221
|
-
let byteLength = Buffer.byteLength(str, this.encoding);
|
|
222
|
-
if (byteLength > this.buf.length - (this.pos + this.endStrLength)) {
|
|
223
|
-
if (this.buf.length < MAX_BUFFER_SIZE) {
|
|
224
|
-
flushed = this.growBuffer(byteLength);
|
|
225
|
-
}
|
|
226
|
-
if (byteLength > this.buf.length - (this.pos + this.endStrLength)) {
|
|
227
|
-
//not enough space in buffer, will stream :
|
|
228
|
-
let strBuf = Buffer.from(str, this.encoding);
|
|
229
|
-
flushed = this.writeBuffer(strBuf, 0, strBuf.length) || flushed;
|
|
230
|
-
return flushed;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
this.pos += this.buf.write(str, this.pos, this.encoding);
|
|
234
|
-
return flushed;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Parameters need to be properly escaped :
|
|
239
|
-
* following characters are to be escaped by "\" :
|
|
240
|
-
* - \0
|
|
241
|
-
* - \\
|
|
242
|
-
* - \'
|
|
243
|
-
* - \"
|
|
244
|
-
* regex split part of string writing part, and escaping special char.
|
|
245
|
-
* Those chars are <= 7f meaning that this will work even with multi-byte encoding
|
|
246
|
-
*
|
|
247
|
-
* @param str string to escape.
|
|
248
|
-
*/
|
|
249
|
-
writeDefaultStringEscapeQuote(str) {
|
|
250
|
-
let flushed = this.writeInt8(QUOTE);
|
|
251
|
-
let match;
|
|
252
|
-
let lastIndex = 0;
|
|
253
|
-
while ((match = CHARS_GLOBAL_REGEXP.exec(str)) !== null) {
|
|
254
|
-
flushed = this.writeString(str.slice(lastIndex, match.index)) || flushed;
|
|
255
|
-
flushed = this.writeInt8(SLASH) || flushed;
|
|
256
|
-
flushed = this.writeInt8(match[0].charCodeAt(0)) || flushed;
|
|
257
|
-
lastIndex = CHARS_GLOBAL_REGEXP.lastIndex;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (lastIndex === 0) {
|
|
261
|
-
// Nothing was escaped
|
|
262
|
-
flushed = this.writeString(str) || flushed;
|
|
263
|
-
flushed = this.writeInt8(QUOTE) || flushed;
|
|
264
|
-
return flushed;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (lastIndex < str.length) {
|
|
268
|
-
flushed = this.writeString(str.slice(lastIndex)) || flushed;
|
|
269
|
-
}
|
|
270
|
-
flushed = this.writeInt8(QUOTE) || flushed;
|
|
271
|
-
return flushed;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
writeBufferEscape(val) {
|
|
275
|
-
let flushed = false;
|
|
276
|
-
let valLen = val.length;
|
|
277
|
-
if (valLen * 2 > this.buf.length - (this.pos + this.endStrLength)) {
|
|
278
|
-
//makes buffer bigger (up to 16M)
|
|
279
|
-
if (this.buf.length < MAX_BUFFER_SIZE) flushed = this.growBuffer(valLen * 2);
|
|
280
|
-
|
|
281
|
-
//data may still be bigger than buffer.
|
|
282
|
-
//must flush buffer when full (and reset position to 4)
|
|
283
|
-
if (valLen * 2 > this.buf.length - (this.pos + this.endStrLength)) {
|
|
284
|
-
//not enough space in buffer, will fill buffer
|
|
285
|
-
for (let i = 0; i < valLen; i++) {
|
|
286
|
-
switch (val[i]) {
|
|
287
|
-
case QUOTE:
|
|
288
|
-
case SLASH:
|
|
289
|
-
case DBL_QUOTE:
|
|
290
|
-
case ZERO_BYTE:
|
|
291
|
-
if (this.pos >= this.buf.length) this.flush(false, (valLen - i) * 2);
|
|
292
|
-
this.buf[this.pos++] = SLASH; //add escape slash
|
|
293
|
-
}
|
|
294
|
-
if (this.pos >= this.buf.length) this.flush(false, (valLen - i) * 2);
|
|
295
|
-
this.buf[this.pos++] = val[i];
|
|
296
|
-
}
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
//sure to have enough place to use buffer directly
|
|
302
|
-
for (let i = 0; i < valLen; i++) {
|
|
303
|
-
switch (val[i]) {
|
|
304
|
-
case QUOTE:
|
|
305
|
-
case SLASH:
|
|
306
|
-
case DBL_QUOTE:
|
|
307
|
-
case ZERO_BYTE:
|
|
308
|
-
this.buf[this.pos++] = SLASH; //add escape slash
|
|
309
|
-
}
|
|
310
|
-
this.buf[this.pos++] = val[i];
|
|
311
|
-
}
|
|
312
|
-
return flushed;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
writeBuffer(arr, off, len) {
|
|
316
|
-
let flushed = false;
|
|
317
|
-
if (len > this.buf.length - (this.pos + this.endStrLength)) {
|
|
318
|
-
if (this.buf.length < MAX_BUFFER_SIZE) flushed = this.growBuffer(len);
|
|
319
|
-
|
|
320
|
-
//max buffer size
|
|
321
|
-
if (len > this.buf.length - (this.pos + this.endStrLength)) {
|
|
322
|
-
//not enough space in buffer, will stream :
|
|
323
|
-
// fill buffer and flush until all data are snd
|
|
324
|
-
let remainingLen = len;
|
|
325
|
-
|
|
326
|
-
while (true) {
|
|
327
|
-
//filling buffer
|
|
328
|
-
let lenToFillBuffer = Math.min(MAX_BUFFER_SIZE - this.pos, remainingLen);
|
|
329
|
-
arr.copy(this.buf, this.pos, off, off + lenToFillBuffer);
|
|
330
|
-
remainingLen -= lenToFillBuffer;
|
|
331
|
-
off += lenToFillBuffer;
|
|
332
|
-
this.pos += lenToFillBuffer;
|
|
333
|
-
|
|
334
|
-
if (remainingLen === 0) return flushed;
|
|
335
|
-
this.flush(false, remainingLen);
|
|
336
|
-
flushed = true;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
arr.copy(this.buf, this.pos, off, off + len);
|
|
341
|
-
this.pos += len;
|
|
342
|
-
return flushed;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
mark(isLast) {
|
|
346
|
-
let flushed = false;
|
|
347
|
-
if (this.singleQuery) {
|
|
348
|
-
//end of big query that is more than 16M
|
|
349
|
-
//write single one
|
|
350
|
-
flushed = this.writeString(this.endStr);
|
|
351
|
-
|
|
352
|
-
if (!this.haveErrorResponse) {
|
|
353
|
-
const packetSendSize =
|
|
354
|
-
this.pos +
|
|
355
|
-
(this.singleQuerySequenceNo != undefined
|
|
356
|
-
? (this.singleQuerySequenceNo + 1) * MAX_BUFFER_SIZE
|
|
357
|
-
: 0);
|
|
358
|
-
if (this.maxAllowedPacket && packetSendSize > this.maxAllowedPacket) {
|
|
359
|
-
console.log(
|
|
360
|
-
"will send a packet to db server with size > connection option 'maxAllowedPacket' (size send is " +
|
|
361
|
-
packetSendSize +
|
|
362
|
-
') connection might be reset by server'
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
this.copyAndFlush(true);
|
|
366
|
-
flushed = true;
|
|
367
|
-
this.markPos = undefined;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
this.singleQuerySequenceNo = undefined;
|
|
371
|
-
this.singleQueryCompressSequenceNo = undefined;
|
|
372
|
-
this.singleQuery = false;
|
|
373
|
-
this.buf[this.pos++] = 0x03;
|
|
374
|
-
this.writeString(this.initStr);
|
|
375
|
-
this.markPos = undefined;
|
|
376
|
-
} else {
|
|
377
|
-
if (this.markPos && this.pos + this.endStrLength > this.maxPacketSize) {
|
|
378
|
-
//not enough room for current query, flush mark.
|
|
379
|
-
this.flushMark();
|
|
380
|
-
flushed = true;
|
|
381
|
-
}
|
|
382
|
-
//just mark ending query
|
|
383
|
-
this.markPos = this.pos;
|
|
384
|
-
if (isLast) {
|
|
385
|
-
this.flushMark();
|
|
386
|
-
flushed = true;
|
|
387
|
-
}
|
|
388
|
-
if (!isLast) flushed = this.writeStringAscii(',') || flushed;
|
|
389
|
-
}
|
|
390
|
-
return flushed;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
flush(end, remainingLen) {
|
|
394
|
-
if (this.markPos && !this.singleQuery) {
|
|
395
|
-
this.flushMark();
|
|
396
|
-
} else {
|
|
397
|
-
//one insert is more than 16M, will continue to mono insert, hoping
|
|
398
|
-
//that max_allowed_packet is sized accordingly to query.
|
|
399
|
-
if (this.buf.length < MAX_BUFFER_SIZE) {
|
|
400
|
-
//in this case, connector has default to 4M packet, and a single query size
|
|
401
|
-
//is > to 4mb. growing buffer to 16M
|
|
402
|
-
let newBuf = Buffer.allocUnsafe(MAX_BUFFER_SIZE);
|
|
403
|
-
this.buf.copy(newBuf, 0, 0, this.pos);
|
|
404
|
-
this.buf = newBuf;
|
|
405
|
-
} else {
|
|
406
|
-
if (!this.haveErrorResponse) {
|
|
407
|
-
if (this.maxAllowedPacket && this.buf.length > this.maxAllowedPacket) {
|
|
408
|
-
console.log(
|
|
409
|
-
"will send a packet to server with size > connection option 'maxAllowedPacket' (size send is " +
|
|
410
|
-
this.pos +
|
|
411
|
-
') connection might be reset by server'
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
this.copyAndFlush(false);
|
|
415
|
-
|
|
416
|
-
this.markPos = undefined;
|
|
417
|
-
if (!this.singleQuery) this.waitingResponseNo++;
|
|
418
|
-
this.singleQuery = true;
|
|
419
|
-
this.singleQuerySequenceNo = this.out.cmd.sequenceNo;
|
|
420
|
-
this.singleQueryCompressSequenceNo = this.out.cmd.compressSequenceNo;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
flushMark() {
|
|
427
|
-
let afterMark;
|
|
428
|
-
if (this.pos !== this.markPos) {
|
|
429
|
-
//remove "," character
|
|
430
|
-
afterMark = Buffer.allocUnsafe(this.pos - this.markPos - 1);
|
|
431
|
-
this.buf.copy(afterMark, 0, this.markPos + 1, this.pos);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
this.pos = this.markPos;
|
|
435
|
-
this.writeString(this.endStr);
|
|
436
|
-
|
|
437
|
-
if (!this.haveErrorResponse) {
|
|
438
|
-
this.copyAndFlush(true);
|
|
439
|
-
this.waitingResponseNo++;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
this.pos = 4;
|
|
443
|
-
this.buf[this.pos++] = 0x03;
|
|
444
|
-
this.writeString(this.initStr);
|
|
445
|
-
this.markPos = undefined;
|
|
446
|
-
if (afterMark) {
|
|
447
|
-
if (this.buf.length - this.pos < afterMark.length)
|
|
448
|
-
this.growBuffer(afterMark.length - (this.buf.length - this.pos));
|
|
449
|
-
afterMark.copy(this.buf, this.pos, 0, afterMark.length);
|
|
450
|
-
this.pos += afterMark.length;
|
|
451
|
-
}
|
|
452
|
-
this.singleQuery = false;
|
|
453
|
-
this.singleQuerySequenceNo = undefined;
|
|
454
|
-
this.singleQueryCompressSequenceNo = undefined;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
copyAndFlush(ended) {
|
|
458
|
-
this.out.buf = this.buf;
|
|
459
|
-
this.out.pos = this.pos;
|
|
460
|
-
if (this.singleQuerySequenceNo != undefined) {
|
|
461
|
-
this.out.cmd.sequenceNo = this.singleQuerySequenceNo;
|
|
462
|
-
this.out.cmd.compressSequenceNo = this.singleQueryCompressSequenceNo;
|
|
463
|
-
} else {
|
|
464
|
-
this.out.cmd.sequenceNo = -1;
|
|
465
|
-
this.out.cmd.compressSequenceNo = -1;
|
|
466
|
-
}
|
|
467
|
-
this.out.flushBuffer(ended);
|
|
468
|
-
if (this.singleQuerySequenceNo != undefined) {
|
|
469
|
-
this.singleQuerySequenceNo = this.out.cmd.sequenceNo;
|
|
470
|
-
this.singleQueryCompressSequenceNo = this.out.cmd.compressSequenceNo;
|
|
471
|
-
}
|
|
472
|
-
this.pos = 4;
|
|
473
|
-
this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
endedWithError() {
|
|
477
|
-
this.haveErrorResponse = true;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
module.exports = ReWritePacket;
|