@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,278 +0,0 @@
1
- 'use strict';
2
-
3
- const CommonBinary = require('./common-binary-cmd');
4
- const Errors = require('../misc/errors');
5
- const Parse = require('../misc/parse');
6
- const BulkPacket = require('../io/bulk-packet');
7
-
8
- /**
9
- * Protocol COM_STMT_BULK_EXECUTE
10
- * see : https://mariadb.com/kb/en/library/com_stmt_bulk_execute/
11
- */
12
- class BatchBulk extends CommonBinary {
13
- constructor(resolve, reject, options, connOpts, sql, values) {
14
- super(resolve, reject, options, connOpts, sql, values);
15
- this.onPacketReceive = this.readPrepareResultPacket;
16
- }
17
-
18
- /**
19
- * Send COM_STMT_BULK_EXECUTE
20
- *
21
- * @param out output writer
22
- * @param opts connection options
23
- * @param info connection information
24
- */
25
- start(out, opts, info) {
26
- this.sending = true;
27
- this.info = info;
28
- this.values = this.initialValues;
29
-
30
- if (this.opts.timeout) {
31
- const err = Errors.createError(
32
- 'Cannot use timeout for Batch statement',
33
- this.sql,
34
- false,
35
- info,
36
- 'HY000',
37
- Errors.ER_TIMEOUT_NOT_SUPPORTED
38
- );
39
- this.emit('send_end');
40
- this.throwError(err, info);
41
- return;
42
- }
43
-
44
- let questionMarkSql = this.sql;
45
- if (this.opts.namedPlaceholders) {
46
- const res = Parse.searchPlaceholder(
47
- this.sql,
48
- info,
49
- this.initialValues,
50
- this.displaySql.bind(this)
51
- );
52
- questionMarkSql = res.sql;
53
- this.values = res.values;
54
- }
55
-
56
- if (!this.validateParameters(info)) {
57
- this.sending = false;
58
- return;
59
- }
60
-
61
- //send COM_STMT_PREPARE command
62
- this.out = out;
63
- this.packet = new BulkPacket(this.opts, out, this.values[0]);
64
-
65
- out.startPacket(this);
66
- out.writeInt8(0x16);
67
- out.writeString(questionMarkSql);
68
- out.flushBuffer(true);
69
-
70
- if (this.opts.pipelining) {
71
- out.startPacket(this);
72
- this.valueIdx = 0;
73
- this.sendQueries();
74
- } else {
75
- this.out = out;
76
- }
77
- }
78
-
79
- sendQueries() {
80
- let flushed = false;
81
- while (!flushed && this.sending && this.valueIdx < this.values.length) {
82
- this.valueRow = this.values[this.valueIdx++];
83
-
84
- //********************************************
85
- // send params
86
- //********************************************
87
- const len = this.valueRow.length;
88
- for (let i = 0; i < len; i++) {
89
- const value = this.valueRow[i];
90
- if (value === null) {
91
- flushed = this.packet.writeInt8(0x01) || flushed;
92
- continue;
93
- }
94
-
95
- //********************************************
96
- // param has no stream. directly write in buffer
97
- //********************************************
98
- flushed = this.writeParam(this.packet, value, this.opts, this.info) || flushed;
99
- }
100
- const last = this.valueIdx === this.values.length;
101
- flushed = this.packet.mark(last, last ? null : this.values[this.valueIdx]) || flushed;
102
- }
103
-
104
- if (this.valueIdx < this.values.length && !this.packet.haveErrorResponse) {
105
- //there is still data to send
106
- setImmediate(this.sendQueries.bind(this));
107
- } else {
108
- if (this.sending && this.valueIdx === this.values.length) this.emit('send_end');
109
- this.sending = false;
110
- }
111
- }
112
-
113
- displaySql() {
114
- if (this.opts && this.initialValues) {
115
- if (this.sql.length > this.opts.debugLen) {
116
- return this.sql.substring(0, this.opts.debugLen) + '...';
117
- }
118
-
119
- let sqlMsg = this.sql + ' - parameters:';
120
- sqlMsg += '[';
121
- for (let i = 0; i < this.initialValues.length; i++) {
122
- if (i !== 0) sqlMsg += ',';
123
- let param = this.initialValues[i];
124
- sqlMsg = this.logParameters(sqlMsg, param);
125
- if (sqlMsg.length > this.opts.debugLen) {
126
- sqlMsg = sqlMsg.substr(0, this.opts.debugLen) + '...';
127
- break;
128
- }
129
- }
130
- sqlMsg += ']';
131
- return sqlMsg;
132
- }
133
- return this.sql + ' - parameters:[]';
134
- }
135
-
136
- success(val) {
137
- this.packet.waitingResponseNo--;
138
-
139
- if (!this.opts.pipelining && this.packet.statementId === -1) {
140
- this.packet.statementId = this.statementId;
141
- this.out.startPacket(this);
142
- this.valueIdx = 0;
143
- this.sendQueries();
144
- this._responseIndex++;
145
- this.onPacketReceive = this.readResponsePacket;
146
- return;
147
- }
148
-
149
- if (!this.sending && this.packet.waitingResponseNo === 0) {
150
- //send COM_STMT_CLOSE packet
151
- if (!this.firstError || !this.firstError.fatal) {
152
- this.sequenceNo = -1;
153
- this.compressSequenceNo = -1;
154
- this.out.startPacket(this);
155
- this.out.writeInt8(0x19);
156
- this.out.writeInt32(this.statementId);
157
- this.out.flushBuffer(true);
158
- }
159
- this.sending = false;
160
- this.emit('send_end');
161
-
162
- if (this.packet.haveErrorResponse) {
163
- this.packet = null;
164
- this.resolve = null;
165
- this.onPacketReceive = null;
166
- this._columns = null;
167
- this._rows = null;
168
- process.nextTick(this.reject, this.firstError);
169
- this.reject = null;
170
- this.emit('end', this.firstError);
171
- } else {
172
- this.packet = null;
173
- let totalAffectedRows = 0;
174
- this._rows.forEach((row) => {
175
- totalAffectedRows += row.affectedRows;
176
- });
177
-
178
- const rs = {
179
- affectedRows: totalAffectedRows,
180
- insertId: this._rows[0].insertId,
181
- warningStatus: this._rows[this._rows.length - 1].warningStatus
182
- };
183
- this.successEnd(rs);
184
- this._columns = null;
185
- this._rows = null;
186
- }
187
- return;
188
- }
189
-
190
- if (!this.packet.haveErrorResponse) {
191
- this._responseIndex++;
192
- this.onPacketReceive = this.readResponsePacket;
193
- }
194
- }
195
-
196
- throwError(err, info) {
197
- this.packet.waitingResponseNo--;
198
- this.sending = false;
199
- if (this.packet && !this.packet.haveErrorResponse) {
200
- if (err.fatal) {
201
- this.packet.waitingResponseNo = 0;
202
- }
203
- if (this.stack) {
204
- err = Errors.createError(
205
- err.message,
206
- this.sql,
207
- err.fatal,
208
- info,
209
- err.sqlState,
210
- err.errno,
211
- this.stack,
212
- false
213
- );
214
- }
215
- this.firstError = err;
216
- this.packet.endedWithError();
217
- }
218
-
219
- if (!this.sending && this.packet.waitingResponseNo === 0) {
220
- this.resolve = null;
221
-
222
- //send COM_STMT_CLOSE packet
223
- if (!err.fatal && this.statementId) {
224
- this.sequenceNo = -1;
225
- this.compressSequenceNo = -1;
226
- this.out.startPacket(this);
227
- this.out.writeInt8(0x19);
228
- this.out.writeInt32(this.statementId);
229
- this.out.flushBuffer(true);
230
- }
231
- this.emit('send_end');
232
- process.nextTick(this.reject, this.firstError);
233
- this.reject = null;
234
- this.onPacketReceive = null;
235
- this.emit('end', this.firstError);
236
- } else {
237
- this._responseIndex++;
238
- this.onPacketReceive = this.readResponsePacket;
239
- }
240
- }
241
-
242
- /**
243
- * Validate that parameters exists and are defined.
244
- *
245
- * @param info connection info
246
- * @returns {boolean} return false if any error occur.
247
- */
248
- validateParameters(info) {
249
- //validate parameter size.
250
- for (let r = 0; r < this.values.length; r++) {
251
- if (!Array.isArray(this.values[r])) this.values[r] = [this.values[r]];
252
-
253
- //validate parameter is defined.
254
- for (let i = 0; i < this.values[r].length; i++) {
255
- if (this.values[r][i] === undefined) {
256
- this.emit('send_end');
257
- this.throwNewError(
258
- 'Parameter at position ' +
259
- (i + 1) +
260
- ' is undefined for values ' +
261
- r +
262
- '\n' +
263
- this.displaySql(),
264
- false,
265
- info,
266
- 'HY000',
267
- Errors.ER_PARAMETER_UNDEFINED
268
- );
269
- return false;
270
- }
271
- }
272
- }
273
-
274
- return true;
275
- }
276
- }
277
-
278
- module.exports = BatchBulk;
@@ -1,372 +0,0 @@
1
- 'use strict';
2
-
3
- const CommonText = require('./common-text-cmd');
4
- const Errors = require('../misc/errors');
5
- const Parse = require('../misc/parse');
6
- const RewritePacket = require('../io/rewrite-packet');
7
- const QUOTE = 0x27;
8
-
9
- /**
10
- * Protocol COM_QUERY
11
- * see : https://mariadb.com/kb/en/library/com_query/
12
- */
13
- class BatchRewrite extends CommonText {
14
- constructor(resolve, reject, options, connOpts, sql, values) {
15
- super(resolve, reject, options, connOpts, sql, values);
16
- }
17
-
18
- /**
19
- * Send COM_QUERY
20
- *
21
- * @param out output writer
22
- * @param opts connection options
23
- * @param info connection information
24
- */
25
- start(out, opts, info) {
26
- this.sending = true;
27
- this.info = info;
28
- if (this.opts.timeout) {
29
- const err = Errors.createError(
30
- 'Cannot use timeout for Batch statement',
31
- this.sql,
32
- false,
33
- info,
34
- 'HY000',
35
- Errors.ER_TIMEOUT_NOT_SUPPORTED
36
- );
37
- this.emit('send_end');
38
- this.throwError(err, info);
39
- return;
40
- }
41
-
42
- if (this.initialValues.length === 0) this.initialValues = [[]];
43
- if (this.opts.namedPlaceholders) {
44
- this.parseResults = Parse.splitRewritableNamedParameterQuery(this.sql, this.initialValues);
45
- this.values = this.parseResults.values;
46
- } else {
47
- this.parseResults = Parse.splitRewritableQuery(this.sql);
48
- this.values = this.initialValues;
49
- if (!this.validateParameters(info)) {
50
- this.sending = false;
51
- return;
52
- }
53
- }
54
-
55
- out.startPacket(this);
56
- this.packet = new RewritePacket(
57
- this.opts.maxAllowedPacket,
58
- out,
59
- this.parseResults.partList[0],
60
- this.parseResults.partList[this.parseResults.partList.length - 1]
61
- );
62
-
63
- this.onPacketReceive = this.readResponsePacket;
64
- this.valueIdx = 0;
65
- this.sendQueries();
66
- }
67
-
68
- sendQueries() {
69
- let flushed = false;
70
- while (!flushed && this.sending && this.valueIdx < this.values.length) {
71
- this.valueRow = this.values[this.valueIdx++];
72
-
73
- //********************************************
74
- // send params
75
- //********************************************
76
- const len = this.parseResults.partList.length - 3;
77
- for (let i = 0; i < len; i++) {
78
- const value = this.valueRow[i];
79
- flushed = this.packet.writeString(this.parseResults.partList[i + 1]) || flushed;
80
- if (value === null) {
81
- flushed = this.packet.writeStringAscii('NULL') || flushed;
82
- continue;
83
- }
84
-
85
- if (
86
- typeof value === 'object' &&
87
- typeof value.pipe === 'function' &&
88
- typeof value.read === 'function'
89
- ) {
90
- //********************************************
91
- // param is stream,
92
- // now all params will be written by event
93
- //********************************************
94
- this.registerStreamSendEvent(this.packet, this.info);
95
- this.currentParam = i;
96
- this.packet.writeInt8(QUOTE); //'
97
-
98
- value.on(
99
- 'data',
100
- function (chunk) {
101
- this.packet.writeBufferEscape(chunk);
102
- }.bind(this)
103
- );
104
-
105
- value.on(
106
- 'end',
107
- function () {
108
- this.packet.writeInt8(QUOTE); //'
109
- this.currentParam++;
110
- this.paramWritten();
111
- }.bind(this)
112
- );
113
-
114
- return;
115
- } else {
116
- //********************************************
117
- // param isn't stream. directly write in buffer
118
- //********************************************
119
- flushed = this.writeParam(this.packet, value, this.opts, this.info) || flushed;
120
- }
121
- }
122
- this.packet.writeString(this.parseResults.partList[this.parseResults.partList.length - 2]);
123
- this.packet.mark(!this.parseResults.reWritable || this.valueIdx === this.values.length);
124
- }
125
-
126
- if (this.valueIdx < this.values.length && !this.packet.haveErrorResponse) {
127
- //there is still data to send
128
- setImmediate(this.sendQueries.bind(this));
129
- } else {
130
- if (this.sending && this.valueIdx === this.values.length) this.emit('send_end');
131
- this.sending = false;
132
- }
133
- }
134
-
135
- displaySql() {
136
- if (this.opts && this.initialValues) {
137
- if (this.sql.length > this.opts.debugLen) {
138
- return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...';
139
- }
140
-
141
- let sqlMsg = 'sql: ' + this.sql + ' - parameters:';
142
- sqlMsg += '[';
143
- for (let i = 0; i < this.initialValues.length; i++) {
144
- if (i !== 0) sqlMsg += ',';
145
- let param = this.initialValues[i];
146
- sqlMsg = this.logParameters(sqlMsg, param);
147
- if (sqlMsg.length > this.opts.debugLen) {
148
- sqlMsg = sqlMsg.substr(0, this.opts.debugLen) + '...';
149
- break;
150
- }
151
- }
152
- sqlMsg += ']';
153
- return sqlMsg;
154
- }
155
- return 'sql: ' + this.sql + ' - parameters:[]';
156
- }
157
-
158
- success(val) {
159
- this.packet.waitingResponseNo--;
160
-
161
- if (this.packet.haveErrorResponse) {
162
- if (!this.sending && this.packet.waitingResponseNo === 0) {
163
- this.packet = null;
164
- this.onPacketReceive = null;
165
- this.resolve = null;
166
- this._columns = null;
167
- this._rows = null;
168
- process.nextTick(this.reject, this.firstError);
169
- this.reject = null;
170
- this.emit('end', this.firstError);
171
- }
172
- } else {
173
- if (!this.sending && this.packet.waitingResponseNo === 0) {
174
- if (this.parseResults.reWritable) {
175
- this.packet = null;
176
- let totalAffectedRows = 0;
177
- this._rows.forEach((row) => {
178
- totalAffectedRows += row.affectedRows;
179
- });
180
-
181
- const rs = {
182
- affectedRows: totalAffectedRows,
183
- insertId: this._rows[0].insertId,
184
- warningStatus: this._rows[this._rows.length - 1].warningStatus
185
- };
186
- this.successEnd(rs);
187
- return;
188
- } else {
189
- this.successEnd(this._rows);
190
- }
191
- this._columns = null;
192
- this._rows = null;
193
- return;
194
- }
195
- this._responseIndex++;
196
- this.onPacketReceive = this.readResponsePacket;
197
- }
198
- }
199
-
200
- throwError(err, info) {
201
- this.packet.waitingResponseNo--;
202
- this.sending = false;
203
-
204
- if (this.packet && !this.packet.haveErrorResponse) {
205
- if (err.fatal) {
206
- this.packet.waitingResponseNo = 0;
207
- }
208
- if (this.stack) {
209
- err = Errors.createError(
210
- err.message,
211
- this.sql,
212
- err.fatal,
213
- info,
214
- err.sqlState,
215
- err.errno,
216
- this.stack,
217
- false
218
- );
219
- }
220
- this.firstError = err;
221
- this.packet.endedWithError();
222
- }
223
-
224
- if (!this.sending && this.packet.waitingResponseNo === 0) {
225
- this.packet = null;
226
- this.onPacketReceive = null;
227
- this.resolve = null;
228
- process.nextTick(this.reject, this.firstError);
229
- this.reject = null;
230
- this.emit('end', this.firstError);
231
- } else {
232
- this._responseIndex++;
233
- this.onPacketReceive = this.readResponsePacket;
234
- }
235
- }
236
-
237
- /**
238
- * Validate that parameters exists and are defined.
239
- *
240
- * @param info connection info
241
- * @returns {boolean} return false if any error occur.
242
- */
243
- validateParameters(info) {
244
- //validate parameter size.
245
- for (let r = 0; r < this.values.length; r++) {
246
- let val = this.values[r];
247
- if (!Array.isArray(val)) {
248
- val = [val];
249
- this.values[r] = val;
250
- }
251
-
252
- if (this.parseResults.partList.length - 3 > val.length) {
253
- this.emit('send_end');
254
- this.throwNewError(
255
- 'Parameter at position ' +
256
- val.length +
257
- ' is not set for values ' +
258
- r +
259
- '\n' +
260
- this.displaySql(),
261
- false,
262
- info,
263
- 'HY000',
264
- Errors.ER_MISSING_PARAMETER
265
- );
266
- return false;
267
- }
268
-
269
- //validate parameter is defined.
270
- for (let i = 0; i < this.parseResults.partList.length - 3; i++) {
271
- if (val[i] === undefined) {
272
- this.emit('send_end');
273
- this.throwNewError(
274
- 'Parameter at position ' +
275
- (i + 1) +
276
- ' is undefined for values ' +
277
- r +
278
- '\n' +
279
- this.displaySql(),
280
- false,
281
- info,
282
- 'HY000',
283
- Errors.ER_PARAMETER_UNDEFINED
284
- );
285
- return false;
286
- }
287
- }
288
- }
289
-
290
- return true;
291
- }
292
-
293
- /**
294
- * Define params events.
295
- * Each parameter indicate that he is written to socket,
296
- * emitting event so next parameter can be written.
297
- */
298
- registerStreamSendEvent(packet, info) {
299
- this.paramWritten = function () {
300
- let flushed = false;
301
- while (!flushed) {
302
- if (this.packet.haveErrorResponse) {
303
- this.sending = false;
304
- this.emit('send_end');
305
- return;
306
- }
307
- if (this.currentParam === this.valueRow.length) {
308
- // all parameters from row are written.
309
- flushed =
310
- packet.writeString(this.parseResults.partList[this.parseResults.partList.length - 2]) ||
311
- flushed;
312
- flushed =
313
- packet.mark(!this.parseResults.reWritable || this.valueIdx === this.values.length) ||
314
- flushed;
315
- if (this.valueIdx < this.values.length) {
316
- // still remaining rows
317
- this.valueRow = this.values[this.valueIdx++];
318
- this.currentParam = 0;
319
- } else {
320
- // all rows are written
321
- this.sending = false;
322
- this.emit('send_end');
323
- return;
324
- }
325
- }
326
-
327
- flushed = packet.writeString(this.parseResults.partList[this.currentParam + 1]) || flushed;
328
- const value = this.valueRow[this.currentParam];
329
-
330
- if (value === null) {
331
- flushed = packet.writeStringAscii('NULL') || flushed;
332
- this.currentParam++;
333
- continue;
334
- }
335
-
336
- if (
337
- typeof value === 'object' &&
338
- typeof value.pipe === 'function' &&
339
- typeof value.read === 'function'
340
- ) {
341
- //********************************************
342
- // param is stream,
343
- //********************************************
344
- flushed = packet.writeInt8(QUOTE) || flushed;
345
- value.once(
346
- 'end',
347
- function () {
348
- packet.writeInt8(QUOTE);
349
- this.currentParam++;
350
- this.paramWritten();
351
- }.bind(this)
352
- );
353
-
354
- value.on('data', function (chunk) {
355
- packet.writeBufferEscape(chunk);
356
- });
357
- return;
358
- }
359
-
360
- //********************************************
361
- // param isn't stream. directly write in buffer
362
- //********************************************
363
- flushed = this.writeParam(packet, value, this.opts, info) || flushed;
364
- this.currentParam++;
365
- }
366
-
367
- if (this.sending) setImmediate(this.paramWritten.bind(this));
368
- }.bind(this);
369
- }
370
- }
371
-
372
- module.exports = BatchRewrite;