@nocobase/plugin-multi-app-manager 2.1.0-alpha.1 → 2.1.0-alpha.11

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 (146) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/dist/client/Migrate.d.ts +10 -0
  4. package/dist/client/e9551d3b66931c0a.js +10 -0
  5. package/dist/client/index.js +1 -1
  6. package/dist/externalVersion.js +7 -7
  7. package/dist/locale/en-US.json +3 -2
  8. package/dist/locale/zh-CN.json +3 -2
  9. package/dist/node_modules/p-queue/dist/index.d.ts +101 -0
  10. package/dist/node_modules/p-queue/dist/index.js +1 -0
  11. package/dist/node_modules/p-queue/dist/lower-bound.d.ts +1 -0
  12. package/dist/node_modules/p-queue/dist/lower-bound.js +21 -0
  13. package/dist/node_modules/p-queue/dist/options.d.ts +64 -0
  14. package/dist/node_modules/p-queue/dist/options.js +2 -0
  15. package/dist/node_modules/p-queue/dist/priority-queue.d.ts +12 -0
  16. package/dist/node_modules/p-queue/dist/priority-queue.js +32 -0
  17. package/dist/node_modules/p-queue/dist/queue.d.ts +7 -0
  18. package/dist/node_modules/p-queue/dist/queue.js +2 -0
  19. package/dist/node_modules/p-queue/license +9 -0
  20. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.d.ts +134 -0
  21. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.js +336 -0
  22. package/dist/node_modules/p-queue/node_modules/eventemitter3/package.json +56 -0
  23. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.js +340 -0
  24. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.min.js +1 -0
  25. package/dist/node_modules/p-queue/package.json +1 -0
  26. package/dist/server/adapters/legacy-adapter.d.ts +43 -0
  27. package/dist/server/adapters/legacy-adapter.js +207 -0
  28. package/dist/server/server.d.ts +4 -6
  29. package/dist/server/server.js +38 -191
  30. package/package.json +3 -3
  31. package/dist/client/db3a142b120d6553.js +0 -10
  32. package/dist/node_modules/mariadb/LICENSE +0 -502
  33. package/dist/node_modules/mariadb/callback.js +0 -41
  34. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
  35. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  36. package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
  37. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
  38. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
  39. package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
  40. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
  41. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
  43. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
  44. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
  45. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
  46. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
  47. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
  48. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
  49. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
  50. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  51. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  52. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
  53. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
  54. package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
  55. package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
  56. package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
  57. package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
  58. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  59. package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
  60. package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
  61. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  62. package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
  63. package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
  64. package/dist/node_modules/mariadb/lib/connection.js +0 -1460
  65. package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
  66. package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
  67. package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
  68. package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
  69. package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
  70. package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
  71. package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
  72. package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
  73. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  74. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  75. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
  76. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
  77. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
  78. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
  79. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
  80. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
  81. package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
  82. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  83. package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
  84. package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
  85. package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
  86. package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
  87. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  88. package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
  89. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  90. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
  91. package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
  92. package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
  93. package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
  94. package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
  95. package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
  96. package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
  97. package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
  98. package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
  99. package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
  100. package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
  101. package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
  102. package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
  103. package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
  104. package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
  105. package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
  106. package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
  107. package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
  108. package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
  109. package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
  110. package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
  111. package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
  112. package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
  113. package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
  114. package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
  115. package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
  116. package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
  117. package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
  118. package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
  119. package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
  120. package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
  121. package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
  122. package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
  123. package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
  124. package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
  125. package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
  126. package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
  127. package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
  128. package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
  129. package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
  130. package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
  131. package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
  132. package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
  133. package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
  134. package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
  135. package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
  136. package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
  137. package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
  138. package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
  139. package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
  140. package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
  141. package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
  142. package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
  143. package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
  144. package/dist/node_modules/mariadb/package.json +0 -1
  145. package/dist/node_modules/mariadb/promise.js +0 -34
  146. package/dist/node_modules/mariadb/types/index.d.ts +0 -870
@@ -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;
@@ -1,96 +0,0 @@
1
- 'use strict';
2
- const Queue = require('denque');
3
-
4
- const _addPacket = function (msg) {
5
- this.lastPackets.push(msg);
6
- while (this.lastPackets.size() > 32) this.lastPackets.shift();
7
- };
8
-
9
- const _getLastPackets = function () {
10
- let output = '';
11
- let packet;
12
- while ((packet = this.lastPackets.shift())) {
13
- output += '\n' + packet;
14
- }
15
- return output;
16
- };
17
-
18
- class ConnectionInformation {
19
- constructor() {
20
- this.threadId = -1;
21
- this.status = null;
22
- this.serverVersion = null;
23
- this.serverCapabilities = null;
24
- }
25
-
26
- addPacket(msg) {}
27
-
28
- getLastPackets() {
29
- return '';
30
- }
31
-
32
- enableLogPacket() {
33
- this.lastPackets = new Queue();
34
- this.addPacket = _addPacket.bind(this);
35
- this.getLastPackets = _getLastPackets.bind(this);
36
- }
37
-
38
- hasMinVersion(major, minor, patch) {
39
- if (!this.serverVersion)
40
- throw new Error('cannot know if server version until connection is established');
41
-
42
- if (!major) throw new Error('a major version must be set');
43
-
44
- if (!minor) minor = 0;
45
- if (!patch) patch = 0;
46
-
47
- let ver = this.serverVersion;
48
- return (
49
- ver.major > major ||
50
- (ver.major === major && ver.minor > minor) ||
51
- (ver.major === major && ver.minor === minor && ver.patch >= patch)
52
- );
53
- }
54
-
55
- isMariaDB() {
56
- if (!this.serverVersion)
57
- throw new Error('cannot know if server is MariaDB until connection is established');
58
- return this.serverVersion.mariaDb;
59
- }
60
-
61
- /**
62
- * Parse raw info to set server major/minor/patch values
63
- * @param info
64
- */
65
- static parseVersionString(info) {
66
- let car;
67
- let offset = 0;
68
- let type = 0;
69
- let val = 0;
70
-
71
- for (; offset < info.serverVersion.raw.length; offset++) {
72
- car = info.serverVersion.raw.charCodeAt(offset);
73
- if (car < 48 || car > 57) {
74
- switch (type) {
75
- case 0:
76
- info.serverVersion.major = val;
77
- break;
78
- case 1:
79
- info.serverVersion.minor = val;
80
- break;
81
- case 2:
82
- info.serverVersion.patch = val;
83
- return;
84
- }
85
- type++;
86
- val = 0;
87
- } else {
88
- val = val * 10 + car - 48;
89
- }
90
- }
91
- //serverVersion finished by number like "5.5.57", assign patchVersion
92
- if (type === 2) info.serverVersion.patch = val;
93
- }
94
- }
95
-
96
- module.exports = ConnectionInformation;
@@ -1,123 +0,0 @@
1
- 'use strict';
2
- const ErrorCodes = require('../const/error-code');
3
-
4
- class SqlError extends Error {
5
- constructor(msg, sql, fatal, info, sqlState, errno, additionalStack, addHeader) {
6
- super(
7
- (addHeader === undefined || addHeader
8
- ? '(conn=' +
9
- (info ? (info.threadId ? info.threadId : -1) : -1) +
10
- ', no: ' +
11
- (errno ? errno : -1) +
12
- ', SQLState: ' +
13
- (sqlState ? sqlState : 'HY000') +
14
- ') '
15
- : '') +
16
- msg +
17
- (sql ? '\nsql: ' + sql : '')
18
- );
19
- this.text = msg;
20
- this.sql = sql;
21
- this.fatal = fatal;
22
- this.errno = errno;
23
- this.sqlState = sqlState;
24
- if (errno > 45000 && errno < 46000) {
25
- //driver error
26
- this.code = errByNo[errno] || 'UNKNOWN';
27
- } else {
28
- this.code = ErrorCodes.codes[this.errno] || 'UNKNOWN';
29
- }
30
- if (additionalStack) {
31
- //adding caller stack, removing initial "Error:\n"
32
- this.stack +=
33
- '\n From event:\n' + additionalStack.substring(additionalStack.indexOf('\n') + 1);
34
- }
35
- }
36
- }
37
-
38
- /**
39
- * Error factory, so error get connection information.
40
- *
41
- * @param msg current error message
42
- * @param sql sql command
43
- * @param fatal is error fatal
44
- * @param info connection information
45
- * @param sqlState sql state
46
- * @param errno error number
47
- * @param additionalStack additional stack trace to see
48
- * @param addHeader add connection information
49
- * @returns {Error} the error
50
- */
51
- module.exports.createError = function (
52
- msg,
53
- sql,
54
- fatal,
55
- info,
56
- sqlState,
57
- errno,
58
- additionalStack,
59
- addHeader
60
- ) {
61
- return new SqlError(msg, sql, fatal, info, sqlState, errno, additionalStack, addHeader);
62
- };
63
-
64
- /********************************************************************************
65
- * Driver specific errors
66
- ********************************************************************************/
67
-
68
- module.exports.ER_CONNECTION_ALREADY_CLOSED = 45001;
69
- module.exports.ER_ALREADY_CONNECTING = 45002;
70
- module.exports.ER_MYSQL_CHANGE_USER_BUG = 45003;
71
- module.exports.ER_CMD_NOT_EXECUTED_DESTROYED = 45004;
72
- module.exports.ER_NULL_CHAR_ESCAPEID = 45005;
73
- module.exports.ER_NULL_ESCAPEID = 45006;
74
- module.exports.ER_NOT_IMPLEMENTED_FORMAT = 45007;
75
- module.exports.ER_NODE_NOT_SUPPORTED_TLS = 45008;
76
- module.exports.ER_SOCKET_UNEXPECTED_CLOSE = 45009;
77
- module.exports.ER_UNEXPECTED_PACKET = 45011;
78
- module.exports.ER_CONNECTION_TIMEOUT = 45012;
79
- module.exports.ER_CMD_CONNECTION_CLOSED = 45013;
80
- module.exports.ER_CHANGE_USER_BAD_PACKET = 45014;
81
- module.exports.ER_PING_BAD_PACKET = 45015;
82
- module.exports.ER_MISSING_PARAMETER = 45016;
83
- module.exports.ER_PARAMETER_UNDEFINED = 45017;
84
- module.exports.ER_PLACEHOLDER_UNDEFINED = 45018;
85
- module.exports.ER_SOCKET = 45019;
86
- module.exports.ER_EOF_EXPECTED = 45020;
87
- module.exports.ER_LOCAL_INFILE_DISABLED = 45021;
88
- module.exports.ER_LOCAL_INFILE_NOT_READABLE = 45022;
89
- module.exports.ER_SERVER_SSL_DISABLED = 45023;
90
- module.exports.ER_AUTHENTICATION_BAD_PACKET = 45024;
91
- module.exports.ER_AUTHENTICATION_PLUGIN_NOT_SUPPORTED = 45025;
92
- module.exports.ER_SOCKET_TIMEOUT = 45026;
93
- module.exports.ER_POOL_ALREADY_CLOSED = 45027;
94
- module.exports.ER_GET_CONNECTION_TIMEOUT = 45028;
95
- module.exports.ER_SETTING_SESSION_ERROR = 45029;
96
- module.exports.ER_INITIAL_SQL_ERROR = 45030;
97
- module.exports.ER_BATCH_WITH_NO_VALUES = 45031;
98
- module.exports.ER_RESET_BAD_PACKET = 45032;
99
- module.exports.ER_WRONG_IANA_TIMEZONE = 45033;
100
- module.exports.ER_LOCAL_INFILE_WRONG_FILENAME = 45034;
101
- module.exports.ER_ADD_CONNECTION_CLOSED_POOL = 45035;
102
- module.exports.ER_WRONG_AUTO_TIMEZONE = 45036;
103
- module.exports.ER_CLOSING_POOL = 45037;
104
- module.exports.ER_TIMEOUT_NOT_SUPPORTED = 45038;
105
- module.exports.ER_INITIAL_TIMEOUT_ERROR = 45039;
106
- module.exports.ER_DUPLICATE_FIELD = 45040;
107
- module.exports.ER_CLIENT_OPTION_INCOMPATIBILITY = 45041;
108
- module.exports.ER_PING_TIMEOUT = 45042;
109
- module.exports.ER_BAD_PARAMETER_VALUE = 45043;
110
- module.exports.ER_CANNOT_RETRIEVE_RSA_KEY = 45044;
111
- module.exports.ER_MINIMUM_NODE_VERSION_REQUIRED = 45045;
112
- module.exports.ER_POOL_UNDEFINED_SQL = 45049;
113
-
114
- const keys = Object.keys(module.exports);
115
- const errByNo = {};
116
- for (let i = 0; i < keys.length; i++) {
117
- const keyName = keys[i];
118
- if (keyName !== 'createError') {
119
- errByNo[module.exports[keyName]] = keyName;
120
- }
121
- }
122
-
123
- module.exports.SqlError = SqlError;