@nocobase/plugin-multi-app-manager 1.2.12-alpha → 1.3.0-alpha.20240710084543

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 (175) hide show
  1. package/package.json +2 -2
  2. package/dist/client/AppManager.d.ts +0 -10
  3. package/dist/client/AppNameInput.d.ts +0 -10
  4. package/dist/client/MultiAppManagerProvider.d.ts +0 -10
  5. package/dist/client/MultiAppManagerProvider.style.d.ts +0 -13
  6. package/dist/client/Settings.d.ts +0 -10
  7. package/dist/client/index.d.ts +0 -14
  8. package/dist/client/index.js +0 -10
  9. package/dist/client/settings/schemas/applications.d.ts +0 -18
  10. package/dist/client/utils.d.ts +0 -12
  11. package/dist/externalVersion.js +0 -25
  12. package/dist/index.d.ts +0 -10
  13. package/dist/index.js +0 -48
  14. package/dist/locale/en-US.json +0 -11
  15. package/dist/locale/es-ES.json +0 -9
  16. package/dist/locale/index.d.ts +0 -9
  17. package/dist/locale/index.js +0 -36
  18. package/dist/locale/ko_KR.json +0 -11
  19. package/dist/locale/pt-BR.json +0 -9
  20. package/dist/locale/zh-CN.json +0 -14
  21. package/dist/node_modules/mariadb/LICENSE +0 -502
  22. package/dist/node_modules/mariadb/callback.js +0 -41
  23. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
  24. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  25. package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
  26. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
  27. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
  28. package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
  29. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
  30. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
  34. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
  35. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
  43. package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
  44. package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
  45. package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
  46. package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
  47. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  48. package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
  49. package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
  50. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  51. package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
  52. package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
  53. package/dist/node_modules/mariadb/lib/connection.js +0 -1460
  54. package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
  55. package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
  56. package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
  57. package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
  58. package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
  59. package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
  60. package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
  61. package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
  62. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  63. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  64. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
  65. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
  66. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
  67. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
  68. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
  69. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
  70. package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
  71. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  72. package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
  73. package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
  74. package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
  75. package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
  76. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  77. package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
  78. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  79. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
  80. package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
  81. package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
  82. package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
  83. package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
  84. package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
  85. package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
  86. package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
  87. package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
  88. package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
  89. package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
  90. package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
  91. package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
  92. package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
  93. package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
  94. package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
  95. package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
  96. package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
  97. package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
  98. package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
  99. package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
  100. package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
  101. package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
  102. package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
  103. package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
  104. package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
  105. package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
  106. package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
  107. package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
  108. package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
  109. package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
  110. package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
  111. package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
  112. package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
  113. package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
  114. package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
  115. package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
  116. package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
  117. package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
  118. package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
  119. package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
  120. package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
  121. package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
  122. package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
  123. package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
  124. package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
  125. package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
  126. package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
  127. package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
  128. package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
  129. package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
  130. package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
  131. package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
  132. package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
  133. package/dist/node_modules/mariadb/node_modules/iconv-lite/.github/dependabot.yml +0 -11
  134. package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/codeStyles/Project.xml +0 -47
  135. package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/codeStyles/codeStyleConfig.xml +0 -5
  136. package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/iconv-lite.iml +0 -12
  137. package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/inspectionProfiles/Project_Default.xml +0 -6
  138. package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/modules.xml +0 -8
  139. package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/vcs.xml +0 -6
  140. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -597
  141. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/dbcs-data.js +0 -188
  142. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/index.js +0 -23
  143. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/internal.js +0 -198
  144. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
  145. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
  146. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/sbcs-data.js +0 -179
  147. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
  148. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
  149. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
  150. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
  151. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
  152. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
  153. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
  154. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
  155. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/utf16.js +0 -197
  156. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/utf32.js +0 -319
  157. package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/utf7.js +0 -290
  158. package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/bom-handling.js +0 -52
  159. package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/index.d.ts +0 -41
  160. package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/index.js +0 -180
  161. package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/streams.js +0 -109
  162. package/dist/node_modules/mariadb/node_modules/iconv-lite/package.json +0 -44
  163. package/dist/node_modules/mariadb/package.json +0 -1
  164. package/dist/node_modules/mariadb/promise.js +0 -34
  165. package/dist/node_modules/mariadb/types/index.d.ts +0 -870
  166. package/dist/server/collections/applications.d.ts +0 -10
  167. package/dist/server/collections/applications.js +0 -75
  168. package/dist/server/index.d.ts +0 -11
  169. package/dist/server/index.js +0 -40
  170. package/dist/server/models/application.d.ts +0 -18
  171. package/dist/server/models/application.js +0 -50
  172. package/dist/server/server.d.ts +0 -26
  173. package/dist/server/server.js +0 -310
  174. package/dist/swagger/index.d.ts +0 -195
  175. package/dist/swagger/index.js +0 -226
@@ -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;