@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,502 +0,0 @@
1
- 'use strict';
2
-
3
- const Iconv = require('iconv-lite');
4
- const Utils = require('../misc/utils');
5
-
6
- const QUOTE = 0x27;
7
- const DBL_QUOTE = 0x22;
8
- const ZERO_BYTE = 0x00;
9
- const SLASH = 0x5c;
10
-
11
- //increase by level to avoid buffer copy.
12
- const SMALL_BUFFER_SIZE = 1024;
13
- const MEDIUM_BUFFER_SIZE = 16384; //16k
14
- const LARGE_BUFFER_SIZE = 131072; //128k
15
- const BIG_BUFFER_SIZE = 1048576; //1M
16
- const MAX_BUFFER_SIZE = 16777219; //16M + 4
17
- const CHARS_GLOBAL_REGEXP = /[\0\"\'\\\b\n\r\t\u001A]/g; // eslint-disable-line no-control-regex
18
-
19
- /**
20
- * MySQL packet builder.
21
- *
22
- * @param opts options
23
- * @param info connection info
24
- * @constructor
25
- */
26
- class PacketOutputStream {
27
- constructor(opts, info) {
28
- this.opts = opts;
29
- this.info = info;
30
- this.pos = 4;
31
- this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
32
- this.changeEncoding(this.opts.collation);
33
- this.changeDebug(this.opts.logPackets, this.opts.debug);
34
-
35
- this.opts.on('collation', this.changeEncoding.bind(this));
36
- this.opts.on('debug', this.changeDebug.bind(this));
37
- }
38
-
39
- changeEncoding(collation) {
40
- this.encoding = collation.charset;
41
- if (this.encoding === 'utf8') {
42
- this.writeString = this.writeDefaultBufferString;
43
- this.writeStringEscapeQuote = this.writeUtf8StringEscapeQuote;
44
- } else if (Buffer.isEncoding(this.encoding)) {
45
- this.writeString = this.writeDefaultBufferString;
46
- this.writeStringEscapeQuote = this.writeDefaultStringEscapeQuote;
47
- } else {
48
- this.writeString = this.writeDefaultIconvString;
49
- this.writeStringEscapeQuote = this.writeDefaultStringEscapeQuote;
50
- }
51
- }
52
-
53
- changeDebug(logPackets, debug) {
54
- this.logPackets = logPackets;
55
- this.debug = debug;
56
- this.flushBuffer =
57
- this.logPackets || this.debug ? this.flushBufferDebug : this.flushBufferBasic;
58
- }
59
-
60
- setStream(stream) {
61
- this.stream = stream;
62
- }
63
-
64
- growBuffer(len) {
65
- let newCapacity;
66
- if (len + this.pos < MEDIUM_BUFFER_SIZE) {
67
- newCapacity = MEDIUM_BUFFER_SIZE;
68
- } else if (len + this.pos < LARGE_BUFFER_SIZE) {
69
- newCapacity = LARGE_BUFFER_SIZE;
70
- } else if (len + this.pos < BIG_BUFFER_SIZE) {
71
- newCapacity = BIG_BUFFER_SIZE;
72
- } else newCapacity = MAX_BUFFER_SIZE;
73
-
74
- let newBuf = Buffer.allocUnsafe(newCapacity);
75
- this.buf.copy(newBuf, 0, 0, this.pos);
76
- this.buf = newBuf;
77
- }
78
-
79
- startPacket(cmd) {
80
- this.cmd = cmd;
81
- this.pos = 4;
82
- }
83
-
84
- writeInt8(value) {
85
- if (this.pos + 1 >= this.buf.length) {
86
- if (this.pos >= MAX_BUFFER_SIZE) {
87
- //buffer is more than a Packet, must flushBuffer()
88
- this.flushBuffer(false, 1);
89
- } else this.growBuffer(1);
90
- }
91
- this.buf[this.pos++] = value;
92
- }
93
-
94
- writeInt16(value) {
95
- if (this.pos + 2 >= this.buf.length) {
96
- let b = Buffer.allocUnsafe(2);
97
- b.writeUInt16LE(value, 0);
98
- this.writeBuffer(b, 0, 2);
99
- return;
100
- }
101
- this.buf[this.pos] = value;
102
- this.buf[this.pos + 1] = value >> 8;
103
- this.pos += 2;
104
- }
105
-
106
- writeInt16AtPos(initPos) {
107
- this.buf[initPos] = this.pos - initPos - 2;
108
- this.buf[initPos + 1] = (this.pos - initPos - 2) >> 8;
109
- }
110
-
111
- writeInt32(value) {
112
- if (this.pos + 4 >= this.buf.length) {
113
- //not enough space remaining
114
- let arr = Buffer.allocUnsafe(4);
115
- arr.writeInt32LE(value, 0);
116
- this.writeBuffer(arr, 0, 4);
117
- return;
118
- }
119
-
120
- this.buf[this.pos] = value;
121
- this.buf[this.pos + 1] = value >> 8;
122
- this.buf[this.pos + 2] = value >> 16;
123
- this.buf[this.pos + 3] = value >> 24;
124
- this.pos += 4;
125
- }
126
-
127
- writeLengthCoded(len) {
128
- //length encoded can be null(0xfb) or bigger than 65k, but only if using binary protocol
129
- //so not implemented for now
130
- if (len < 0xfb) {
131
- this.writeInt8(len);
132
- return;
133
- }
134
-
135
- //max length is len < 0xffff
136
- this.writeInt8(0xfc);
137
- this.writeInt16(len);
138
- }
139
-
140
- writeBuffer(arr, off, len) {
141
- if (len > this.buf.length - this.pos) {
142
- if (this.buf.length !== MAX_BUFFER_SIZE) {
143
- this.growBuffer(len);
144
- }
145
-
146
- //max buffer size
147
- if (len > this.buf.length - this.pos) {
148
- //not enough space in buffer, will stream :
149
- // fill buffer and flush until all data are snd
150
- let remainingLen = len;
151
-
152
- while (true) {
153
- //filling buffer
154
- let lenToFillBuffer = Math.min(MAX_BUFFER_SIZE - this.pos, remainingLen);
155
- arr.copy(this.buf, this.pos, off, off + lenToFillBuffer);
156
- remainingLen -= lenToFillBuffer;
157
- off += lenToFillBuffer;
158
- this.pos += lenToFillBuffer;
159
-
160
- if (remainingLen === 0) return;
161
- this.flushBuffer(false, remainingLen);
162
- }
163
- }
164
- }
165
- arr.copy(this.buf, this.pos, off, off + len);
166
- this.pos += len;
167
- }
168
-
169
- /**
170
- * Write ascii string to socket (no escaping)
171
- *
172
- * @param str string
173
- */
174
- writeStringAscii(str) {
175
- let len = str.length;
176
-
177
- //not enough space remaining
178
- if (len >= this.buf.length - this.pos) {
179
- let strBuf = Buffer.from(str, 'ascii');
180
- this.writeBuffer(strBuf, 0, strBuf.length);
181
- return;
182
- }
183
-
184
- for (let off = 0; off < len; ) {
185
- this.buf[this.pos++] = str.charCodeAt(off++);
186
- }
187
- }
188
-
189
- writeUtf8StringEscapeQuote(str) {
190
- const charsLength = str.length;
191
-
192
- //not enough space remaining
193
- if (charsLength * 3 + 2 >= this.buf.length - this.pos) {
194
- const arr = Buffer.from(str, 'utf8');
195
- this.writeInt8(QUOTE);
196
- this.writeBufferEscape(arr);
197
- this.writeInt8(QUOTE);
198
- return;
199
- }
200
-
201
- //create UTF-8 byte array
202
- //since javascript char are internally using UTF-16 using surrogate's pattern, 4 bytes unicode characters will
203
- //represent 2 characters : example "\uD83C\uDFA4" = 🎤 unicode 8 "no microphones"
204
- //so max size is 3 * charLength
205
- //(escape characters are 1 byte encoded, so length might only be 2 when escaped)
206
- // + 2 for the quotes for text protocol
207
- let charsOffset = 0;
208
- let currChar;
209
- this.buf[this.pos++] = QUOTE;
210
- //quick loop if only ASCII chars for faster escape
211
- for (
212
- ;
213
- charsOffset < charsLength && (currChar = str.charCodeAt(charsOffset)) < 0x80;
214
- charsOffset++
215
- ) {
216
- if (
217
- currChar === SLASH ||
218
- currChar === QUOTE ||
219
- currChar === ZERO_BYTE ||
220
- currChar === DBL_QUOTE
221
- ) {
222
- this.buf[this.pos++] = SLASH;
223
- }
224
- this.buf[this.pos++] = currChar;
225
- }
226
-
227
- //if quick loop not finished
228
- while (charsOffset < charsLength) {
229
- currChar = str.charCodeAt(charsOffset++);
230
- if (currChar < 0x80) {
231
- if (
232
- currChar === SLASH ||
233
- currChar === QUOTE ||
234
- currChar === ZERO_BYTE ||
235
- currChar === DBL_QUOTE
236
- ) {
237
- this.buf[this.pos++] = SLASH;
238
- }
239
- this.buf[this.pos++] = currChar;
240
- } else if (currChar < 0x800) {
241
- this.buf[this.pos++] = 0xc0 | (currChar >> 6);
242
- this.buf[this.pos++] = 0x80 | (currChar & 0x3f);
243
- } else if (currChar >= 0xd800 && currChar < 0xe000) {
244
- //reserved for surrogate - see https://en.wikipedia.org/wiki/UTF-16
245
- if (currChar < 0xdc00) {
246
- //is high surrogate
247
- if (charsOffset + 1 > charsLength) {
248
- this.buf[this.pos++] = 0x3f;
249
- } else {
250
- const nextChar = str.charCodeAt(charsOffset);
251
- if (nextChar >= 0xdc00 && nextChar < 0xe000) {
252
- //is low surrogate
253
- const surrogatePairs =
254
- (currChar << 10) + nextChar + (0x010000 - (0xd800 << 10) - 0xdc00);
255
- this.buf[this.pos++] = 0xf0 | (surrogatePairs >> 18);
256
- this.buf[this.pos++] = 0x80 | ((surrogatePairs >> 12) & 0x3f);
257
- this.buf[this.pos++] = 0x80 | ((surrogatePairs >> 6) & 0x3f);
258
- this.buf[this.pos++] = 0x80 | (surrogatePairs & 0x3f);
259
- charsOffset++;
260
- } else {
261
- //must have low surrogate
262
- this.buf[this.pos++] = 0x3f;
263
- }
264
- }
265
- } else {
266
- //low surrogate without high surrogate before
267
- this.buf[this.pos++] = 0x3f;
268
- }
269
- } else {
270
- this.buf[this.pos++] = 0xe0 | (currChar >> 12);
271
- this.buf[this.pos++] = 0x80 | ((currChar >> 6) & 0x3f);
272
- this.buf[this.pos++] = 0x80 | (currChar & 0x3f);
273
- }
274
- }
275
- this.buf[this.pos++] = QUOTE;
276
- }
277
-
278
- writeDefaultBufferString(str) {
279
- //javascript use UCS-2 or UTF-16 string internal representation
280
- //that means that string to byte will be a maximum of * 3
281
- // (4 bytes utf-8 are represented on 2 UTF-16 characters)
282
- if (str.length * 3 < this.buf.length - this.pos) {
283
- this.pos += this.buf.write(str, this.pos, this.encoding);
284
- return;
285
- }
286
-
287
- //checking real length
288
- let byteLength = Buffer.byteLength(str, this.encoding);
289
- if (byteLength > this.buf.length - this.pos) {
290
- if (this.buf.length < MAX_BUFFER_SIZE) {
291
- this.growBuffer(byteLength);
292
- }
293
- if (byteLength > this.buf.length - this.pos) {
294
- //not enough space in buffer, will stream :
295
- let strBuf = Buffer.from(str, this.encoding);
296
- this.writeBuffer(strBuf, 0, strBuf.length);
297
- return;
298
- }
299
- }
300
- this.pos += this.buf.write(str, this.pos, this.encoding);
301
- }
302
-
303
- writeDefaultIconvString(str) {
304
- let buf = Iconv.encode(str, this.encoding);
305
- this.writeBuffer(buf, 0, buf.length);
306
- }
307
-
308
- /**
309
- * Parameters need to be properly escaped :
310
- * following characters are to be escaped by "\" :
311
- * - \0
312
- * - \\
313
- * - \'
314
- * - \"
315
- * regex split part of string writing part, and escaping special char.
316
- * Those chars are <= 7f meaning that this will work even with multi-byte encoding
317
- *
318
- * @param str string to escape.
319
- */
320
- writeDefaultStringEscapeQuote(str) {
321
- this.writeInt8(QUOTE);
322
- let match;
323
- let lastIndex = 0;
324
- while ((match = CHARS_GLOBAL_REGEXP.exec(str)) !== null) {
325
- this.writeString(str.slice(lastIndex, match.index));
326
- this.writeInt8(SLASH);
327
- this.writeInt8(match[0].charCodeAt(0));
328
- lastIndex = CHARS_GLOBAL_REGEXP.lastIndex;
329
- }
330
-
331
- if (lastIndex === 0) {
332
- // Nothing was escaped
333
- this.writeString(str);
334
- this.writeInt8(QUOTE);
335
- return;
336
- }
337
-
338
- if (lastIndex < str.length) {
339
- this.writeString(str.slice(lastIndex));
340
- }
341
- this.writeInt8(QUOTE);
342
- }
343
-
344
- writeBufferEscape(val) {
345
- let valLen = val.length;
346
- if (valLen * 2 > this.buf.length - this.pos) {
347
- //makes buffer bigger (up to 16M)
348
- if (this.buf.length !== MAX_BUFFER_SIZE) this.growBuffer(valLen * 2);
349
-
350
- //data may still be bigger than buffer.
351
- //must flush buffer when full (and reset position to 4)
352
- if (valLen * 2 > this.buf.length - this.pos) {
353
- //not enough space in buffer, will fill buffer
354
- for (let i = 0; i < valLen; i++) {
355
- switch (val[i]) {
356
- case QUOTE:
357
- case SLASH:
358
- case DBL_QUOTE:
359
- case ZERO_BYTE:
360
- if (this.pos >= this.buf.length) this.flushBuffer(false, (valLen - i) * 2);
361
- this.buf[this.pos++] = SLASH; //add escape slash
362
- }
363
- if (this.pos >= this.buf.length) this.flushBuffer(false, (valLen - i) * 2);
364
- this.buf[this.pos++] = val[i];
365
- }
366
- return;
367
- }
368
- }
369
-
370
- //sure to have enough place to use buffer directly
371
- for (let i = 0; i < valLen; i++) {
372
- switch (val[i]) {
373
- case QUOTE:
374
- case SLASH:
375
- case DBL_QUOTE:
376
- case ZERO_BYTE:
377
- this.buf[this.pos++] = SLASH; //add escape slash
378
- }
379
- this.buf[this.pos++] = val[i];
380
- }
381
- }
382
-
383
- /**
384
- * Indicate if buffer contain any data.
385
- * @returns {boolean}
386
- */
387
- isEmpty() {
388
- return this.pos <= 4;
389
- }
390
-
391
- /**
392
- * Flush the internal buffer.
393
- */
394
- flushBufferDebug(commandEnd, remainingLen) {
395
- this.buf[0] = this.pos - 4;
396
- this.buf[1] = (this.pos - 4) >>> 8;
397
- this.buf[2] = (this.pos - 4) >>> 16;
398
- this.buf[3] = ++this.cmd.sequenceNo;
399
-
400
- this.stream.writeBuf(this.buf.slice(0, this.pos), this.cmd);
401
-
402
- const packet = Utils.log(this.opts, this.buf, 0, this.pos);
403
- if (this.opts.logPackets) {
404
- this.info.addPacket(
405
- '==> conn:' +
406
- (this.info.threadId ? this.info.threadId : -1) +
407
- ' ' +
408
- this.cmd.constructor.name +
409
- '(0,' +
410
- this.pos +
411
- ')\n' +
412
- packet
413
- );
414
- }
415
-
416
- if (this.opts.debug) {
417
- console.log(
418
- '==> conn:%d %s\n%s',
419
- this.info.threadId ? this.info.threadId : -1,
420
- this.cmd.constructor.name + '(0,' + this.pos + ')',
421
- Utils.log(this.opts, this.buf, 0, this.pos)
422
- );
423
- }
424
-
425
- if (commandEnd) {
426
- //if last packet fill the max size, must send an empty com to indicate that command end.
427
- if (this.pos === MAX_BUFFER_SIZE) {
428
- this.writeEmptyPacket();
429
- } else {
430
- this.stream.flush(true, this.cmd);
431
- this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
432
- }
433
- } else {
434
- this.buf = allocateBuffer(remainingLen + 4);
435
- this.pos = 4;
436
- }
437
- }
438
-
439
- flushBufferBasic(commandEnd, remainingLen) {
440
- this.buf[0] = this.pos - 4;
441
- this.buf[1] = (this.pos - 4) >>> 8;
442
- this.buf[2] = (this.pos - 4) >>> 16;
443
- this.buf[3] = ++this.cmd.sequenceNo;
444
- this.stream.writeBuf(this.buf.slice(0, this.pos), this.cmd);
445
- if (commandEnd) {
446
- //if last packet fill the max size, must send an empty com to indicate that command end.
447
- if (this.pos === MAX_BUFFER_SIZE) {
448
- this.writeEmptyPacket();
449
- } else {
450
- this.stream.flush(true, this.cmd);
451
- this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
452
- }
453
- } else {
454
- this.buf = allocateBuffer(remainingLen + 4);
455
- this.pos = 4;
456
- }
457
- }
458
-
459
- writeEmptyPacket() {
460
- const emptyBuf = Buffer.from([0x00, 0x00, 0x00, ++this.cmd.sequenceNo]);
461
-
462
- if (this.opts.logPackets || this.opts.debug) {
463
- const packet = Utils.log(this.opts, emptyBuf, 0, 4);
464
- if (this.opts.logPackets) {
465
- this.info.addPacket(
466
- '==> conn:' +
467
- (this.info.threadId ? this.info.threadId : -1) +
468
- ' ' +
469
- this.cmd.constructor.name +
470
- '(0,4)\n' +
471
- packet
472
- );
473
- }
474
- if (this.opts.debug) {
475
- console.log(
476
- '==> conn:%d %s\n%s',
477
- this.info.threadId ? this.info.threadId : -1,
478
- this.cmd.constructor.name + '(0,4)',
479
- packet
480
- );
481
- }
482
- }
483
-
484
- this.stream.writeBuf(emptyBuf, this.cmd);
485
- this.stream.flush(true, this.cmd);
486
- }
487
- }
488
-
489
- function allocateBuffer(len) {
490
- if (len < SMALL_BUFFER_SIZE) {
491
- return Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
492
- } else if (len < MEDIUM_BUFFER_SIZE) {
493
- return Buffer.allocUnsafe(MEDIUM_BUFFER_SIZE);
494
- } else if (len < LARGE_BUFFER_SIZE) {
495
- return Buffer.allocUnsafe(LARGE_BUFFER_SIZE);
496
- } else if (len < BIG_BUFFER_SIZE) {
497
- return Buffer.allocUnsafe(BIG_BUFFER_SIZE);
498
- }
499
- return Buffer.allocUnsafe(MAX_BUFFER_SIZE);
500
- }
501
-
502
- module.exports = PacketOutputStream;