@nocobase/plugin-multi-app-manager 2.0.0-alpha.7 → 2.0.0-alpha.71

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 (161) hide show
  1. package/dist/client/00b71fff3c8c7167.js +10 -0
  2. package/dist/client/Migrate.d.ts +10 -0
  3. package/dist/client/index.d.ts +1 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client/settings/schemas/applications.d.ts +63 -1
  6. package/dist/externalVersion.js +8 -7
  7. package/dist/locale/de-DE.json +19 -7
  8. package/dist/locale/en-US.json +21 -7
  9. package/dist/locale/es-ES.json +23 -6
  10. package/dist/locale/fr-FR.json +26 -0
  11. package/dist/locale/hu-HU.json +26 -0
  12. package/dist/locale/id-ID.json +26 -0
  13. package/dist/locale/it-IT.json +19 -7
  14. package/dist/locale/ja-JP.json +18 -6
  15. package/dist/locale/ko-KR.json +22 -7
  16. package/dist/locale/nl-NL.json +24 -9
  17. package/dist/locale/pt-BR.json +23 -6
  18. package/dist/locale/ru-RU.json +26 -0
  19. package/dist/locale/tr-TR.json +26 -0
  20. package/dist/locale/uk-UA.json +26 -0
  21. package/dist/locale/vi-VN.json +26 -0
  22. package/dist/locale/zh-CN.json +17 -15
  23. package/dist/locale/zh-TW.json +26 -0
  24. package/dist/node_modules/p-queue/dist/index.d.ts +101 -0
  25. package/dist/node_modules/p-queue/dist/index.js +1 -0
  26. package/dist/node_modules/p-queue/dist/lower-bound.d.ts +1 -0
  27. package/dist/node_modules/p-queue/dist/lower-bound.js +21 -0
  28. package/dist/node_modules/p-queue/dist/options.d.ts +64 -0
  29. package/dist/node_modules/p-queue/dist/options.js +2 -0
  30. package/dist/node_modules/p-queue/dist/priority-queue.d.ts +12 -0
  31. package/dist/node_modules/p-queue/dist/priority-queue.js +32 -0
  32. package/dist/node_modules/p-queue/dist/queue.d.ts +7 -0
  33. package/dist/node_modules/p-queue/dist/queue.js +2 -0
  34. package/dist/node_modules/p-queue/license +9 -0
  35. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.d.ts +134 -0
  36. package/dist/node_modules/p-queue/node_modules/eventemitter3/index.js +336 -0
  37. package/dist/node_modules/p-queue/node_modules/eventemitter3/package.json +56 -0
  38. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.js +340 -0
  39. package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.min.js +1 -0
  40. package/dist/node_modules/p-queue/package.json +1 -0
  41. package/dist/server/adapters/legacy-adapter.d.ts +43 -0
  42. package/dist/server/adapters/legacy-adapter.js +207 -0
  43. package/dist/server/server.d.ts +7 -6
  44. package/dist/server/server.js +110 -186
  45. package/package.json +5 -2
  46. package/dist/client/bd12299af6cdc73a.js +0 -10
  47. package/dist/node_modules/mariadb/LICENSE +0 -502
  48. package/dist/node_modules/mariadb/callback.js +0 -41
  49. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
  50. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  51. package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
  52. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
  53. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
  54. package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
  55. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
  56. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  57. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
  58. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
  59. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
  60. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
  61. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
  62. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
  63. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
  64. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
  65. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  66. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  67. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
  68. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
  69. package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
  70. package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
  71. package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
  72. package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
  73. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  74. package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
  75. package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
  76. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  77. package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
  78. package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
  79. package/dist/node_modules/mariadb/lib/connection.js +0 -1460
  80. package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
  81. package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
  82. package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
  83. package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
  84. package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
  85. package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
  86. package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
  87. package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
  88. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  89. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  90. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
  91. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
  92. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
  93. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
  94. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
  95. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
  96. package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
  97. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  98. package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
  99. package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
  100. package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
  101. package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
  102. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  103. package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
  104. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  105. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
  106. package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
  107. package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
  108. package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
  109. package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
  110. package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
  111. package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
  112. package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
  113. package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
  114. package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
  115. package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
  116. package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
  117. package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
  118. package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
  119. package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
  120. package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
  121. package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
  122. package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
  123. package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
  124. package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
  125. package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
  126. package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
  127. package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
  128. package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
  129. package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
  130. package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
  131. package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
  132. package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
  133. package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
  134. package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
  135. package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
  136. package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
  137. package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
  138. package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
  139. package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
  140. package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
  141. package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
  142. package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
  143. package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
  144. package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
  145. package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
  146. package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
  147. package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
  148. package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
  149. package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
  150. package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
  151. package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
  152. package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
  153. package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
  154. package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
  155. package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
  156. package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
  157. package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
  158. package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
  159. package/dist/node_modules/mariadb/package.json +0 -1
  160. package/dist/node_modules/mariadb/promise.js +0 -34
  161. package/dist/node_modules/mariadb/types/index.d.ts +0 -870
@@ -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;