@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,611 +0,0 @@
1
- 'use strict';
2
-
3
- const EventEmitter = require('events');
4
- const util = require('util');
5
- const Queue = require('denque');
6
- const Errors = require('./misc/errors');
7
- const Utils = require('./misc/utils');
8
-
9
- function PoolBase(options, processTask, createConnectionPool, pingPromise) {
10
- //*****************************************************************
11
- // public methods
12
- //*****************************************************************
13
-
14
- /**
15
- * Retrieve a connection from pool.
16
- * Create a new one, if limit is not reached.
17
- * wait until acquireTimeout.
18
- *
19
- * @return {Promise}
20
- */
21
- this.getConnection = function () {
22
- return addRequest(this);
23
- };
24
-
25
- /**
26
- * Execute a query on one connection from pool.
27
- *
28
- * @param sql sql command
29
- * @param value parameter value of sql command (not mandatory)
30
- * @return {Promise}
31
- */
32
- this.query = function (sql, value) {
33
- return addRequest(this, sql, value, false);
34
- };
35
-
36
- /**
37
- * Execute a batch on one connection from pool.
38
- *
39
- * @param sql sql command
40
- * @param value parameter value of sql command (not mandatory)
41
- * @return {Promise}
42
- */
43
- this.batch = function (sql, value) {
44
- return addRequest(this, sql, value, true);
45
- };
46
-
47
- /**
48
- * Close all connection in pool
49
- *
50
- * @return Promise
51
- */
52
- this.end = function () {
53
- if (closed) {
54
- return Promise.reject(
55
- Errors.createError(
56
- 'pool is already closed',
57
- null,
58
- false,
59
- null,
60
- 'HY000',
61
- Errors.ER_POOL_ALREADY_CLOSED,
62
- undefined,
63
- false
64
- )
65
- );
66
- }
67
- closed = true;
68
- clearInterval(idleMaintainingTask);
69
-
70
- //close unused connections
71
- const idleConnectionsEndings = [];
72
- let conn;
73
- while ((conn = idleConnections.shift())) {
74
- idleConnectionsEndings.push(conn.forceEnd());
75
- }
76
-
77
- firstTaskTimeout = clearTimeout(firstTaskTimeout);
78
-
79
- //reject all waiting task
80
- if (taskQueue.size() > 0) {
81
- let task;
82
- const err = Errors.createError(
83
- 'pool is ending, connection request aborted',
84
- null,
85
- false,
86
- null,
87
- 'HY000',
88
- Errors.ER_CLOSING_POOL,
89
- undefined,
90
- false
91
- );
92
- while ((task = taskQueue.shift())) {
93
- process.nextTick(task.reject, err);
94
- }
95
- }
96
-
97
- return Promise.all(idleConnectionsEndings);
98
- };
99
-
100
- /**
101
- * Get current active connections.
102
- * @return {number}
103
- */
104
- this.activeConnections = function () {
105
- return Object.keys(activeConnections).length;
106
- };
107
-
108
- /**
109
- * Get current total connection number.
110
- * @return {number}
111
- */
112
- this.totalConnections = function () {
113
- return this.activeConnections() + this.idleConnections();
114
- };
115
-
116
- /**
117
- * Get current idle connection number.
118
- * @return {number}
119
- */
120
- this.idleConnections = function () {
121
- return idleConnections.size();
122
- };
123
-
124
- /**
125
- * Get current stacked connection request.
126
- * @return {number}
127
- */
128
- this.taskQueueSize = function () {
129
- return taskQueue.size();
130
- };
131
-
132
- /**
133
- * First connection creation.
134
- * activation is slightly different than pooling grow : If connection fails, there is many retries for 30s
135
- * (option initializationTimeout).
136
- * If connection fails, error will be thrown to request / console if no request, to ensure that error is thrown.
137
- */
138
- this.initialize = function () {
139
- connectionInCreation = true;
140
- const self = this;
141
- const timeoutEnd = Date.now() + opts.initializationTimeout;
142
- connectionCreationLoop(self, 0, timeoutEnd)
143
- .then((conn) => {
144
- //add to pool
145
- if (closed) {
146
- conn.forceEnd().catch((err) => {});
147
- } else {
148
- addPoolConnection(self, conn);
149
- if (opts.idleTimeout > 0) {
150
- idleMaintainingTask = setInterval(idleMaintainer, 500, self);
151
- }
152
- }
153
- })
154
- .catch((err) => {
155
- connectionInCreation = false;
156
- const task = taskQueue.shift();
157
- if (task) {
158
- firstTaskTimeout = clearTimeout(firstTaskTimeout);
159
- process.nextTick(task.reject, err);
160
- resetTimeoutToNextTask();
161
- } else if (!closed) {
162
- console.error(err);
163
- }
164
- })
165
- .finally(() => {
166
- ensurePoolSize(self);
167
- });
168
- };
169
-
170
- this.escape = (value) => {
171
- return Utils.escape(options.connOptions, searchInfo(), value);
172
- };
173
-
174
- this.escapeId = (value) => {
175
- return Utils.escapeId(options.connOptions, searchInfo(), value);
176
- };
177
-
178
- //*****************************************************************
179
- // internal methods
180
- //*****************************************************************
181
-
182
- /**
183
- * Search info object of an existing connection. to know server type and version.
184
- * @returns information object if connection available.
185
- */
186
- const searchInfo = () => {
187
- let info = null;
188
- let conn = idleConnections.get(0);
189
-
190
- if (conn == null) {
191
- conn = Object.keys(activeConnections)[0];
192
- }
193
-
194
- if (conn != null) {
195
- info = conn.info;
196
- }
197
- return info;
198
- };
199
-
200
- /**
201
- * Get a connection from pool / execute query
202
- *
203
- * @param pool current pool
204
- * @param sql sql value (not mandatory)
205
- * @param values sql parameter (not mandatory)
206
- * @param isBatch is batch request
207
- * @return {*}
208
- */
209
- const addRequest = function (pool, sql, values, isBatch) {
210
- if (isBatch != undefined && !sql) {
211
- // request for query/batch without sql
212
- return Promise.reject(
213
- Errors.createError(
214
- 'sql parameter is mandatory',
215
- null,
216
- false,
217
- null,
218
- 'HY000',
219
- Errors.ER_POOL_UNDEFINED_SQL,
220
- undefined,
221
- false
222
- )
223
- );
224
- }
225
-
226
- if (closed) {
227
- return Promise.reject(
228
- Errors.createError(
229
- 'pool is closed',
230
- null,
231
- false,
232
- null,
233
- 'HY000',
234
- Errors.ER_POOL_ALREADY_CLOSED,
235
- undefined,
236
- false
237
- )
238
- );
239
- }
240
-
241
- return getIdleValidConnection(pool).then(
242
- (conn) => {
243
- pool.emit('acquire', conn);
244
- return processTask(conn, sql, values, isBatch);
245
- },
246
- () => {
247
- process.nextTick(() => pool.emit('enqueue'));
248
-
249
- //no idle connection available
250
- //create a new connection if limit is not reached
251
- ensurePoolSize(pool);
252
-
253
- //connections are all used, stack demand.
254
- return new Promise((resolve, reject) => {
255
- const task = {
256
- timeout: Date.now() + opts.acquireTimeout,
257
- reject: reject,
258
- resolve: resolve,
259
- sql: sql,
260
- values: values,
261
- isBatch: isBatch
262
- };
263
- if (!firstTaskTimeout) {
264
- firstTaskTimeout = setTimeout(rejectAndResetTimeout, opts.acquireTimeout, task);
265
- }
266
- taskQueue.push(task);
267
- });
268
- }
269
- );
270
- };
271
-
272
- /**
273
- * Return an idle Connection.
274
- * If connection has not been used for some time ( minDelayValidation), validate connection status.
275
- *
276
- * @param pool pool
277
- * @returns {Promise<Connection|null>)} connection of null of no valid idle connection.
278
- */
279
- const getIdleValidConnection = function (pool) {
280
- if (idleConnections.isEmpty()) {
281
- return Promise.reject(null);
282
- }
283
- const conn = idleConnections.shift();
284
- activeConnections[conn.threadId] = conn;
285
- if (opts.minDelayValidation <= 0 || Date.now() - conn.lastUse > opts.minDelayValidation) {
286
- return pingPromise(conn)
287
- .then(() => {
288
- initLeakProcess(conn);
289
- return Promise.resolve(conn);
290
- })
291
- .catch((err) => {
292
- delete activeConnections[conn.threadId];
293
- pool.emit('_remove-conn');
294
- return getIdleValidConnection(pool);
295
- });
296
- } else {
297
- //just check connection state
298
- if (conn.isValid()) {
299
- initLeakProcess(conn);
300
- return Promise.resolve(conn);
301
- } else {
302
- delete activeConnections[conn.threadId];
303
- pool.emit('_remove-conn');
304
- return getIdleValidConnection(pool);
305
- }
306
- }
307
- };
308
-
309
- /**
310
- * Task request timeout handler
311
- * @param task
312
- */
313
- const timeoutTask = (task) => {
314
- firstTaskTimeout = null;
315
- if (task === taskQueue.peekFront()) {
316
- taskQueue.shift();
317
- process.nextTick(
318
- task.reject,
319
- Errors.createError(
320
- 'retrieve connection from pool timeout after ' +
321
- Math.abs(Date.now() - (task.timeout - opts.acquireTimeout)) +
322
- 'ms',
323
- null,
324
- false,
325
- null,
326
- 'HY000',
327
- Errors.ER_GET_CONNECTION_TIMEOUT,
328
- undefined,
329
- false
330
- )
331
- );
332
- } else {
333
- throw new Error('Rejection by timeout without task !!!');
334
- }
335
- };
336
-
337
- /**
338
- * Reject task, and reset timeout to next waiting task if any.
339
- * @param task
340
- */
341
- const rejectAndResetTimeout = (task) => {
342
- timeoutTask(task);
343
- resetTimeoutToNextTask();
344
- };
345
-
346
- /**
347
- * Loop for connection creation.
348
- * This permits to wait before next try after a connection fail.
349
- *
350
- * @param pool current pool
351
- * @param iteration current iteration
352
- * @param timeoutEnd ending timeout
353
- * @returns {Promise<any>} Connection if found, error if not
354
- */
355
- const connectionCreationLoop = function (pool, iteration, timeoutEnd) {
356
- return new Promise(function (resolve, reject) {
357
- const creationTryout = function (resolve, reject) {
358
- if (closed) {
359
- reject(
360
- Errors.createError(
361
- 'Cannot create new connection to pool, pool closed',
362
- null,
363
- true,
364
- null,
365
- '08S01',
366
- Errors.ER_ADD_CONNECTION_CLOSED_POOL,
367
- null
368
- )
369
- );
370
- return;
371
- }
372
- iteration++;
373
- createConnectionPool(pool)
374
- .then((conn) => {
375
- resolve(conn);
376
- })
377
- .catch((err) => {
378
- //if timeout is reached or authentication fail return error
379
- if (
380
- closed ||
381
- (err.errno && (err.errno === 1524 || err.errno === 1045 || err.errno === 1698)) ||
382
- timeoutEnd < Date.now()
383
- ) {
384
- reject(err);
385
- return;
386
- }
387
-
388
- setTimeout(creationTryout.bind(null, resolve, reject), 500);
389
- });
390
- };
391
- //initial without timeout
392
- creationTryout(resolve, reject);
393
- });
394
- };
395
-
396
- const addPoolConnection = function (pool, conn) {
397
- conn.lastUse = Date.now();
398
- const initialDestroyFct = conn.destroy;
399
- conn.destroy = () => {
400
- removeLeakProcess(conn);
401
- delete activeConnections[conn.threadId];
402
- initialDestroyFct();
403
- pool.emit('_remove-conn');
404
- };
405
-
406
- //Connection error
407
- // -> evict connection from pool
408
- conn.on('error', (err) => {
409
- let idx = 0;
410
- let currConn;
411
- removeLeakProcess(conn);
412
- delete activeConnections[conn.threadId];
413
- while ((currConn = idleConnections.peekAt(idx))) {
414
- if (currConn === conn) {
415
- idleConnections.removeOne(idx);
416
- break;
417
- } else {
418
- //since connection did have an error, other waiting connection might too
419
- //forcing validation when borrowed next time, even if "minDelayValidation" is not reached.
420
- currConn.lastUse = Math.min(Date.now() - opts.minDelayValidation, currConn.lastUse);
421
- }
422
- idx++;
423
- }
424
- pool.emit('_remove-conn');
425
- });
426
- connectionInCreation = false;
427
- idleConnections.push(conn);
428
- pool.emit('_idle-conn');
429
- process.nextTick(() => pool.emit('connection', conn));
430
- };
431
-
432
- this._releaseConnection = function (conn) {
433
- removeLeakProcess(conn);
434
- conn.lastUse = Date.now();
435
- delete activeConnections[conn.threadId];
436
- const pool = this;
437
- if (closed) {
438
- return conn.forceEnd().catch(() => {
439
- return Promise.resolve();
440
- });
441
- } else if (conn.isValid()) {
442
- pool.emit('release', conn);
443
- idleConnections.push(conn);
444
- process.nextTick(() => pool.emit('_idle-conn'));
445
- } else {
446
- ensurePoolSize(pool);
447
- }
448
- };
449
-
450
- /**
451
- * Grow pool connections until reaching connection limit.
452
- */
453
- const ensurePoolSize = function (pool) {
454
- if (
455
- !connectionInCreation &&
456
- pool.idleConnections() < opts.minimumIdle &&
457
- pool.totalConnections() < opts.connectionLimit &&
458
- !closed
459
- ) {
460
- connectionInCreation = true;
461
- process.nextTick(() => {
462
- const timeoutEnd = Date.now() + opts.initializationTimeout;
463
- if (!closed) {
464
- connectionCreationLoop(pool, 0, timeoutEnd)
465
- .then((conn) => {
466
- if (closed) {
467
- return conn.forceEnd().catch((err) => {});
468
- }
469
- addPoolConnection(pool, conn);
470
- })
471
- .catch((err) => {
472
- if (pool.totalConnections() === 0) {
473
- const task = taskQueue.shift();
474
- if (task) {
475
- firstTaskTimeout = clearTimeout(firstTaskTimeout);
476
- process.nextTick(task.reject, err);
477
- resetTimeoutToNextTask();
478
- }
479
- } else if (!closed) {
480
- console.error(`pool fail to create connection (${err.message})`);
481
- }
482
-
483
- //delay next try
484
- setTimeout(() => {
485
- connectionInCreation = false;
486
- if (taskQueue.size() > 0) {
487
- ensurePoolSize(pool);
488
- }
489
- }, 500);
490
- });
491
- }
492
- });
493
- }
494
- };
495
-
496
- const resetTimeoutToNextTask = () => {
497
- //handle next Timer
498
- const currTime = Date.now();
499
- let nextTask;
500
- while ((nextTask = taskQueue.peekFront())) {
501
- if (nextTask.timeout < currTime) {
502
- timeoutTask(nextTask);
503
- } else {
504
- firstTaskTimeout = setTimeout(rejectAndResetTimeout, nextTask.timeout - currTime, nextTask);
505
- return;
506
- }
507
- }
508
- };
509
-
510
- /**
511
- * Permit to remove idle connection if unused for some time.
512
- * @param pool current pool
513
- */
514
- const idleMaintainer = function (pool) {
515
- let toRemove = Math.max(1, pool.idleConnections() - opts.minimumIdle);
516
- while (toRemove > 0) {
517
- const conn = idleConnections.peek();
518
- --toRemove;
519
- if (conn && conn.lastUse + opts.idleTimeout * 1000 < Date.now()) {
520
- idleConnections.shift();
521
- conn.forceEnd().catch((err) => {});
522
- continue;
523
- }
524
- break;
525
- }
526
- ensurePoolSize(pool);
527
- };
528
-
529
- this._discardConnection = (conn) => {
530
- removeLeakProcess(conn);
531
- delete activeConnections[conn.threadId];
532
- conn.forceEnd().catch((err) => {});
533
- this.emit('_remove-conn');
534
- };
535
-
536
- const logLeak = (conn) => {
537
- console.log(
538
- 'Possible connection leak on thread ' +
539
- conn.info.threadId +
540
- ' (connection not returned to pool since ' +
541
- (Date.now() - conn.lastUse) +
542
- 'ms. Did connection.released() been implemented'
543
- );
544
- conn.leaked = true;
545
- };
546
-
547
- const _initLeakProcess = (conn) => {
548
- conn.lastUse = Date.now();
549
- conn.leaked = false;
550
- conn.leakProcess = setTimeout(logLeak, opts.leakDetectionTimeout, conn);
551
- };
552
-
553
- const _removeLeakProcess = (conn) => {
554
- conn.leakProcess = clearTimeout(conn.leakProcess);
555
- if (conn.leaked) {
556
- console.log(
557
- 'Previous possible leak connection with thread ' +
558
- conn.info.threadId +
559
- ' was returned to pool'
560
- );
561
- }
562
- };
563
-
564
- /**
565
- * Launch next waiting task request if available connections.
566
- */
567
- const handleTaskQueue = function () {
568
- firstTaskTimeout = clearTimeout(firstTaskTimeout);
569
- const task = taskQueue.shift();
570
-
571
- if (task) {
572
- const conn = idleConnections.shift();
573
- if (conn) {
574
- initLeakProcess(conn);
575
- this.emit('acquire', conn);
576
- activeConnections[conn.threadId] = conn;
577
- resetTimeoutToNextTask();
578
- processTask(conn, task.sql, task.values, task.isBatch)
579
- .then(task.resolve)
580
- .catch(task.reject);
581
- } else {
582
- taskQueue.unshift(task);
583
- }
584
- }
585
- };
586
-
587
- const opts = options;
588
- let closed = false;
589
- let connectionInCreation = false;
590
- const initLeakProcess = opts.leakDetectionTimeout > 0 ? _initLeakProcess : () => {};
591
- const removeLeakProcess = opts.leakDetectionTimeout > 0 ? _removeLeakProcess : () => {};
592
- const idleConnections = new Queue();
593
- const activeConnections = {};
594
- const taskQueue = new Queue();
595
- let idleMaintainingTask;
596
- let firstTaskTimeout;
597
- Object.defineProperty(this, 'closed', {
598
- get() {
599
- return closed;
600
- }
601
- });
602
-
603
- EventEmitter.call(this);
604
-
605
- this.on('_idle-conn', handleTaskQueue.bind(this));
606
- this.on('_remove-conn', ensurePoolSize.bind(this, this));
607
- this.on('connection', ensurePoolSize.bind(this, this));
608
- }
609
-
610
- util.inherits(PoolBase, EventEmitter);
611
- module.exports = PoolBase;