@tachybase/module-multi-app 0.23.8

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 (117) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/README.md +34 -0
  3. package/README.zh-CN.md +34 -0
  4. package/client.d.ts +1 -0
  5. package/client.js +1 -0
  6. package/dist/client/AppManager.d.ts +2 -0
  7. package/dist/client/AppNameInput.d.ts +2 -0
  8. package/dist/client/MultiAppBlockInitializer.d.ts +2 -0
  9. package/dist/client/MultiAppManagerProvider.d.ts +2 -0
  10. package/dist/client/MultiAppManagerProvider.style.d.ts +5 -0
  11. package/dist/client/Settings.d.ts +2 -0
  12. package/dist/client/index.d.ts +6 -0
  13. package/dist/client/index.js +1 -0
  14. package/dist/client/settings/schemas/applications.d.ts +13 -0
  15. package/dist/client/utils.d.ts +4 -0
  16. package/dist/constants.d.ts +1 -0
  17. package/dist/constants.js +27 -0
  18. package/dist/externalVersion.js +16 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +39 -0
  21. package/dist/locale/en-US.json +27 -0
  22. package/dist/locale/es-ES.json +9 -0
  23. package/dist/locale/ko_KR.json +11 -0
  24. package/dist/locale/pt-BR.json +9 -0
  25. package/dist/locale/zh-CN.json +27 -0
  26. package/dist/node_modules/mariadb/LICENSE +502 -0
  27. package/dist/node_modules/mariadb/callback.js +41 -0
  28. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +278 -0
  29. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +372 -0
  30. package/dist/node_modules/mariadb/lib/cmd/change-user.js +149 -0
  31. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +17 -0
  32. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +102 -0
  33. package/dist/node_modules/mariadb/lib/cmd/command.js +168 -0
  34. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +327 -0
  35. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +427 -0
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +168 -0
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +23 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +761 -0
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +55 -0
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +58 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +19 -0
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +142 -0
  43. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +74 -0
  44. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +126 -0
  45. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +292 -0
  46. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +74 -0
  47. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +29 -0
  48. package/dist/node_modules/mariadb/lib/cmd/ping.js +52 -0
  49. package/dist/node_modules/mariadb/lib/cmd/query.js +255 -0
  50. package/dist/node_modules/mariadb/lib/cmd/quit.js +28 -0
  51. package/dist/node_modules/mariadb/lib/cmd/reset.js +54 -0
  52. package/dist/node_modules/mariadb/lib/cmd/resultset.js +607 -0
  53. package/dist/node_modules/mariadb/lib/cmd/stream.js +45 -0
  54. package/dist/node_modules/mariadb/lib/config/connection-options.js +258 -0
  55. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +19 -0
  56. package/dist/node_modules/mariadb/lib/config/pool-options.js +47 -0
  57. package/dist/node_modules/mariadb/lib/connection-callback.js +160 -0
  58. package/dist/node_modules/mariadb/lib/connection.js +1460 -0
  59. package/dist/node_modules/mariadb/lib/const/capabilities.js +64 -0
  60. package/dist/node_modules/mariadb/lib/const/collations.js +473 -0
  61. package/dist/node_modules/mariadb/lib/const/connection_status.js +13 -0
  62. package/dist/node_modules/mariadb/lib/const/error-code.js +1282 -0
  63. package/dist/node_modules/mariadb/lib/const/field-detail.js +35 -0
  64. package/dist/node_modules/mariadb/lib/const/field-type.js +71 -0
  65. package/dist/node_modules/mariadb/lib/const/server-status.js +30 -0
  66. package/dist/node_modules/mariadb/lib/const/state-change.js +12 -0
  67. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +81 -0
  68. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +590 -0
  69. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +141 -0
  70. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +171 -0
  71. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +193 -0
  72. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +36 -0
  73. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +37 -0
  74. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +502 -0
  75. package/dist/node_modules/mariadb/lib/io/packet.js +515 -0
  76. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +481 -0
  77. package/dist/node_modules/mariadb/lib/misc/connection-information.js +96 -0
  78. package/dist/node_modules/mariadb/lib/misc/errors.js +123 -0
  79. package/dist/node_modules/mariadb/lib/misc/parse.js +1033 -0
  80. package/dist/node_modules/mariadb/lib/misc/utils.js +298 -0
  81. package/dist/node_modules/mariadb/lib/pool-base.js +611 -0
  82. package/dist/node_modules/mariadb/lib/pool-callback.js +202 -0
  83. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +66 -0
  84. package/dist/node_modules/mariadb/lib/pool-cluster.js +407 -0
  85. package/dist/node_modules/mariadb/lib/pool-promise.js +108 -0
  86. package/dist/node_modules/mariadb/package.json +1 -0
  87. package/dist/node_modules/mariadb/promise.js +34 -0
  88. package/dist/node_modules/mariadb/types/index.d.ts +870 -0
  89. package/dist/server/actions/apps.d.ts +5 -0
  90. package/dist/server/actions/apps.js +117 -0
  91. package/dist/server/app-lifecycle.d.ts +8 -0
  92. package/dist/server/app-lifecycle.js +99 -0
  93. package/dist/server/app-start-env.d.ts +2 -0
  94. package/dist/server/app-start-env.js +105 -0
  95. package/dist/server/collections/applications.d.ts +2 -0
  96. package/dist/server/collections/applications.js +82 -0
  97. package/dist/server/index.d.ts +4 -0
  98. package/dist/server/index.js +29 -0
  99. package/dist/server/middlewares/app-selector.d.ts +1 -0
  100. package/dist/server/middlewares/app-selector.js +47 -0
  101. package/dist/server/middlewares/index.d.ts +2 -0
  102. package/dist/server/middlewares/index.js +23 -0
  103. package/dist/server/middlewares/inject-app-list.d.ts +1 -0
  104. package/dist/server/middlewares/inject-app-list.js +48 -0
  105. package/dist/server/migrations/20240820153000-add-apps-tmpl.d.ts +6 -0
  106. package/dist/server/migrations/20240820153000-add-apps-tmpl.js +47 -0
  107. package/dist/server/migrations/20241126124904-add-createdBy.d.ts +6 -0
  108. package/dist/server/migrations/20241126124904-add-createdBy.js +41 -0
  109. package/dist/server/models/application.d.ts +10 -0
  110. package/dist/server/models/application.js +57 -0
  111. package/dist/server/server.d.ts +19 -0
  112. package/dist/server/server.js +246 -0
  113. package/dist/swagger/index.d.ts +197 -0
  114. package/dist/swagger/index.js +227 -0
  115. package/package.json +38 -0
  116. package/server.d.ts +2 -0
  117. package/server.js +1 -0
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const Query = require('./query');
4
+ const { Readable } = require('stream');
5
+
6
+ /**
7
+ * Protocol COM_QUERY with streaming events.
8
+ * see : https://mariadb.com/kb/en/library/com_query/
9
+ */
10
+ class Stream extends Query {
11
+ constructor(cmdOpts, connOpts, sql, values, socket) {
12
+ super(
13
+ () => {},
14
+ () => {},
15
+ cmdOpts,
16
+ connOpts,
17
+ sql,
18
+ values
19
+ );
20
+ this.socket = socket;
21
+ this.inStream = new Readable({
22
+ objectMode: true,
23
+ read: () => {}
24
+ });
25
+
26
+ this.on('fields', function (meta) {
27
+ this.inStream.emit('fields', meta);
28
+ });
29
+
30
+ this.on('error', function (err) {
31
+ this.inStream.emit('error', err);
32
+ });
33
+
34
+ this.on('end', function (err) {
35
+ if (err) this.inStream.emit('error', err);
36
+ this.inStream.push(null);
37
+ });
38
+ }
39
+
40
+ handleNewRows(row) {
41
+ this.inStream.push(row);
42
+ }
43
+ }
44
+
45
+ module.exports = Stream;
@@ -0,0 +1,258 @@
1
+ 'use strict';
2
+
3
+ const Collations = require('../const/collations.js');
4
+ const urlFormat = /mariadb:\/\/(([^/@:]+)?(:([^/]+))?@)?(([^/:]+)(:([0-9]+))?)\/([^?]+)(\?(.*))?$/;
5
+ const moment = require('moment-timezone');
6
+ const Errors = require('../misc/errors');
7
+
8
+ /**
9
+ * Default option similar to mysql driver.
10
+ * known differences
11
+ * - no queryFormat option. Permitting client to parse is a security risk. Best is to give SQL + parameters
12
+ * Only possible Objects are :
13
+ * - Buffer
14
+ * - Date
15
+ * - Object that implement toSqlString function
16
+ * - JSON object
17
+ * + rowsAsArray (in mysql2) permit to have rows by index, not by name. Avoiding to parsing metadata string => faster
18
+ */
19
+ class ConnectionOptions {
20
+ constructor(opts) {
21
+ if (typeof opts === 'string') {
22
+ opts = ConnectionOptions.parse(opts);
23
+ }
24
+
25
+ if (!opts) opts = {};
26
+ this.host = opts.host || 'localhost';
27
+ this.port = opts.port || 3306;
28
+ this.user = opts.user || process.env.USERNAME;
29
+ this.password = opts.password;
30
+ this.database = opts.database;
31
+ if (opts.charset && typeof opts.charset === 'string') {
32
+ this.collation = Collations.fromCharset(opts.charset.toLowerCase());
33
+ if (this.collation === undefined) {
34
+ this.collation = Collations.fromName(opts.charset.toUpperCase());
35
+ if (this.collation !== undefined) {
36
+ console.log(
37
+ "warning: please use option 'collation' " +
38
+ "in replacement of 'charset' when using a collation name ('" +
39
+ opts.charset +
40
+ "')\n" +
41
+ "(collation looks like 'UTF8MB4_UNICODE_CI', charset like 'utf8')."
42
+ );
43
+ }
44
+ }
45
+ if (this.collation === undefined)
46
+ throw new RangeError("Unknown charset '" + opts.charset + "'");
47
+ } else if (opts.collation && typeof opts.collation === 'string') {
48
+ this.collation = Collations.fromName(opts.collation.toUpperCase());
49
+ if (this.collation === undefined)
50
+ throw new RangeError("Unknown collation '" + opts.collation + "'");
51
+ } else {
52
+ this.collation = Collations.fromIndex(opts.charsetNumber) || Collations.fromIndex(224); //UTF8MB4_UNICODE_CI;
53
+ }
54
+
55
+ // connection options
56
+ this.initSql = opts.initSql;
57
+ this.connectTimeout = opts.connectTimeout === undefined ? 1000 : opts.connectTimeout;
58
+ this.connectAttributes = opts.connectAttributes || false;
59
+ this.compress = opts.compress || false;
60
+ this.rsaPublicKey = opts.rsaPublicKey;
61
+ this.cachingRsaPublicKey = opts.cachingRsaPublicKey;
62
+ this.allowPublicKeyRetrieval = opts.allowPublicKeyRetrieval || false;
63
+ this.forceVersionCheck = opts.forceVersionCheck || false;
64
+ this.maxAllowedPacket = opts.maxAllowedPacket;
65
+ this.permitConnectionWhenExpired = opts.permitConnectionWhenExpired || false;
66
+ this.pipelining = opts.pipelining;
67
+ this.timezone = opts.timezone || 'local';
68
+ this.socketPath = opts.socketPath;
69
+ this.sessionVariables = opts.sessionVariables;
70
+ this.ssl = opts.ssl;
71
+ if (opts.ssl) {
72
+ if (typeof opts.ssl !== 'boolean' && typeof opts.ssl !== 'string') {
73
+ this.ssl.rejectUnauthorized = opts.ssl.rejectUnauthorized !== false;
74
+ }
75
+ }
76
+
77
+ // socket
78
+ this.queryTimeout = opts.queryTimeout === undefined ? 0 : opts.queryTimeout;
79
+ this.socketTimeout = opts.socketTimeout === undefined ? 0 : opts.socketTimeout;
80
+ this.keepAliveDelay = opts.keepAliveDelay === undefined ? 0 : opts.keepAliveDelay;
81
+
82
+ // log
83
+ this.debug = opts.debug || false;
84
+ this.debugCompress = opts.debugCompress || false;
85
+ this.debugLen = opts.debugLen || 256;
86
+ this.logPackets = opts.logPackets || false;
87
+ this.trace = opts.trace || false;
88
+
89
+ // result-set
90
+ this.checkDuplicate = opts.checkDuplicate === undefined ? true : opts.checkDuplicate;
91
+ this.dateStrings = opts.dateStrings || false;
92
+ this.foundRows = opts.foundRows === undefined || opts.foundRows;
93
+ this.metaAsArray = opts.metaAsArray || false;
94
+ this.multipleStatements = opts.multipleStatements || false;
95
+ this.namedPlaceholders = opts.namedPlaceholders || false;
96
+ this.nestTables = opts.nestTables;
97
+ this.autoJsonMap = opts.autoJsonMap === undefined ? true : opts.autoJsonMap;
98
+ this.arrayParenthesis = opts.arrayParenthesis || false;
99
+ this.permitSetMultiParamEntries = opts.permitSetMultiParamEntries || false;
100
+ this.rowsAsArray = opts.rowsAsArray || false;
101
+ this.supportBigNumbers = opts.supportBigNumbers || false;
102
+ this.supportBigInt = opts.supportBigInt || false;
103
+ this.skipSetTimezone = opts.skipSetTimezone || false;
104
+ this.typeCast = opts.typeCast;
105
+ if (this.typeCast !== undefined && typeof this.typeCast !== 'function') {
106
+ this.typeCast = undefined;
107
+ }
108
+ this.bigNumberStrings = opts.bigNumberStrings || false;
109
+ this.bulk = opts.bulk === undefined || opts.bulk;
110
+
111
+ // coherence check
112
+ if (opts.pipelining === undefined) {
113
+ this.permitLocalInfile = opts.permitLocalInfile || false;
114
+ this.pipelining = !this.permitLocalInfile;
115
+ } else {
116
+ this.pipelining = opts.pipelining;
117
+ if (opts.permitLocalInfile === true && this.pipelining) {
118
+ throw new Error(
119
+ 'enabling options `permitLocalInfile` and `pipelining` is not possible, options are incompatible.'
120
+ );
121
+ }
122
+ this.permitLocalInfile = this.pipelining ? false : opts.permitLocalInfile || false;
123
+ }
124
+ if (this.maxAllowedPacket && !Number.isInteger(this.maxAllowedPacket)) {
125
+ throw new RangeError(
126
+ "maxAllowedPacket must be an integer. was '" + this.maxAllowedPacket + "'"
127
+ );
128
+ }
129
+ if (this.timezone && this.timezone !== 'local' && this.timezone !== 'auto') {
130
+ let tzName = this.timezone;
131
+ if (this.timezone === 'Z') {
132
+ tzName = 'Etc/UTC';
133
+ } else {
134
+ const matched = this.timezone.match(/([+\-\s])(\d\d):?(\d\d)?/);
135
+ if (matched) {
136
+ const hour = (matched[1] === '-' ? 1 : -1) * Number.parseInt(matched[2], 10);
137
+ const minutes = matched.length > 2 && matched[3] ? Number.parseInt(matched[3], 10) : 0;
138
+ if (minutes > 0) {
139
+ throw new RangeError(
140
+ "timezone format incompatible with IANA standard timezone format was '" +
141
+ this.timezone +
142
+ "'"
143
+ );
144
+ }
145
+ if (hour == 0) {
146
+ tzName = 'Etc/UTC';
147
+ } else {
148
+ tzName = 'Etc/GMT' + (matched[1] === '-' ? '+' : '') + hour;
149
+ }
150
+ }
151
+ }
152
+ this._localTz = moment.tz.guess();
153
+ if (tzName === this._localTz) {
154
+ this.tz = null;
155
+ } else {
156
+ this.tz = tzName;
157
+ if (!moment.tz.zone(tzName)) {
158
+ throw Errors.createError(
159
+ "Unknown IANA timezone '" + tzName + "'.",
160
+ null,
161
+ true,
162
+ null,
163
+ '08S01',
164
+ Errors.ER_WRONG_IANA_TIMEZONE
165
+ );
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ /**
172
+ * When parsing from String, correcting type.
173
+ *
174
+ * @param opts options
175
+ * @return {opts}
176
+ */
177
+ static parseOptionDataType(opts) {
178
+ if (opts.bigNumberStrings) opts.bigNumberStrings = opts.bigNumberStrings == 'true';
179
+ if (opts.bulk) opts.bulk = opts.bulk == 'true';
180
+ if (opts.rsaPublicKey) opts.rsaPublicKey = opts.rsaPublicKey;
181
+ if (opts.cachingRsaPublicKey) opts.cachingRsaPublicKey = opts.cachingRsaPublicKey;
182
+ if (opts.logPackets) opts.logPackets = opts.logPackets == 'true';
183
+ if (opts.allowPublicKeyRetrieval)
184
+ opts.allowPublicKeyRetrieval = opts.allowPublicKeyRetrieval == 'true';
185
+
186
+ if (opts.charsetNumber && !isNaN(Number.parseInt(opts.charsetNumber))) {
187
+ opts.charsetNumber = Number.parseInt(opts.charsetNumber);
188
+ }
189
+ if (opts.compress) opts.compress = opts.compress == 'true';
190
+ if (opts.connectAttributes) opts.connectAttributes = JSON.parse(opts.connectAttributes);
191
+ if (opts.connectTimeout) opts.connectTimeout = parseInt(opts.connectTimeout);
192
+ if (opts.keepAliveDelay) opts.keepAliveDelay = parseInt(opts.keepAliveDelay);
193
+ if (opts.socketTimeout) opts.socketTimeout = parseInt(opts.socketTimeout);
194
+ if (opts.dateStrings) opts.dateStrings = opts.dateStrings == 'true';
195
+ if (opts.debug) opts.debug = opts.debug == 'true';
196
+ if (opts.autoJsonMap) opts.autoJsonMap = opts.autoJsonMap == 'true';
197
+ if (opts.arrayParenthesis) opts.arrayParenthesis = opts.arrayParenthesis == 'true';
198
+ if (opts.skipSetTimezone) opts.skipSetTimezone = opts.skipSetTimezone == 'true';
199
+
200
+ if (opts.checkDuplicate) opts.checkDuplicate = opts.checkDuplicate == 'true';
201
+ if (opts.debugCompress) opts.debugCompress = opts.debugCompress == 'true';
202
+ if (opts.debugLen) opts.debugLen = parseInt(opts.debugLen);
203
+ if (opts.queryTimeout) opts.queryTimeout = parseInt(opts.queryTimeout);
204
+ if (opts.foundRows) opts.foundRows = opts.foundRows == 'true';
205
+ if (opts.maxAllowedPacket && !isNaN(Number.parseInt(opts.maxAllowedPacket)))
206
+ opts.maxAllowedPacket = parseInt(opts.maxAllowedPacket);
207
+ if (opts.metaAsArray) opts.metaAsArray = opts.metaAsArray == 'true';
208
+ if (opts.multipleStatements) opts.multipleStatements = opts.multipleStatements == 'true';
209
+ if (opts.namedPlaceholders) opts.namedPlaceholders = opts.namedPlaceholders == 'true';
210
+ if (opts.nestTables) opts.nestTables = opts.nestTables == 'true';
211
+ if (opts.permitSetMultiParamEntries)
212
+ opts.permitSetMultiParamEntries = opts.permitSetMultiParamEntries == 'true';
213
+ if (opts.pipelining) opts.pipelining = opts.pipelining == 'true';
214
+ if (opts.forceVersionCheck) opts.forceVersionCheck = opts.forceVersionCheck == 'true';
215
+ if (opts.rowsAsArray) opts.rowsAsArray = opts.rowsAsArray == 'true';
216
+ if (opts.supportBigNumbers) opts.supportBigNumbers = opts.supportBigNumbers == 'true';
217
+ if (opts.supportBigInt) opts.supportBigInt = opts.supportBigInt == 'true';
218
+ if (opts.trace) opts.trace = opts.trace == 'true';
219
+ if (opts.ssl && (opts.ssl == 'true' || opts.ssl == 'false')) opts.ssl = opts.ssl == 'true';
220
+ return opts;
221
+ }
222
+
223
+ static parse(opts) {
224
+ const matchResults = opts.match(urlFormat);
225
+
226
+ if (!matchResults) {
227
+ throw new Error(
228
+ "error parsing connection string '" +
229
+ opts +
230
+ "'. format must be 'mariadb://[<user>[:<password>]@]<host>[:<port>]/[<db>[?<opt1>=<value1>[&<opt2>=<value2>]]]'"
231
+ );
232
+ }
233
+ const options = {
234
+ user: matchResults[2] ? decodeURIComponent(matchResults[2]) : undefined,
235
+ password: matchResults[4] ? decodeURIComponent(matchResults[4]) : undefined,
236
+ host: matchResults[6] ? decodeURIComponent(matchResults[6]) : matchResults[6],
237
+ port: matchResults[8] ? parseInt(matchResults[8]) : undefined,
238
+ database: matchResults[9] ? decodeURIComponent(matchResults[9]) : matchResults[9]
239
+ };
240
+
241
+ const variousOptsString = matchResults[11];
242
+ if (variousOptsString) {
243
+ const keyVals = variousOptsString.split('&');
244
+ keyVals.forEach(function (keyVal) {
245
+ const equalIdx = keyVal.indexOf('=');
246
+ if (equalIdx !== 1) {
247
+ let val = keyVal.substring(equalIdx + 1);
248
+ val = val ? decodeURIComponent(val) : undefined;
249
+ options[keyVal.substring(0, equalIdx)] = val;
250
+ }
251
+ });
252
+ }
253
+
254
+ return this.parseOptionDataType(options);
255
+ }
256
+ }
257
+
258
+ module.exports = ConnectionOptions;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ class PoolClusterOptions {
4
+ constructor(opts) {
5
+ if (opts) {
6
+ this.canRetry = opts.canRetry === undefined ? true : opts.canRetry;
7
+ this.removeNodeErrorCount = opts.removeNodeErrorCount || 5;
8
+ this.restoreNodeTimeout = opts.restoreNodeTimeout || 1000;
9
+ this.defaultSelector = opts.defaultSelector || 'RR';
10
+ } else {
11
+ this.canRetry = true;
12
+ this.removeNodeErrorCount = 5;
13
+ this.restoreNodeTimeout = 1000;
14
+ this.defaultSelector = 'RR';
15
+ }
16
+ }
17
+ }
18
+
19
+ module.exports = PoolClusterOptions;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ let ConnOptions = require('./connection-options');
4
+
5
+ class PoolOptions {
6
+ constructor(opts) {
7
+ if (typeof opts === 'string') {
8
+ opts = ConnOptions.parse(opts);
9
+
10
+ //set data type
11
+ if (opts.acquireTimeout) opts.acquireTimeout = parseInt(opts.acquireTimeout);
12
+ if (opts.connectionLimit) opts.connectionLimit = parseInt(opts.connectionLimit);
13
+ if (opts.idleTimeout) opts.idleTimeout = parseInt(opts.idleTimeout);
14
+ if (opts.leakDetectionTimeout)
15
+ opts.leakDetectionTimeout = parseInt(opts.leakDetectionTimeout);
16
+ if (opts.initializationTimeout)
17
+ opts.initializationTimeout = parseInt(opts.initializationTimeout);
18
+ if (opts.minDelayValidation) opts.minDelayValidation = parseInt(opts.minDelayValidation);
19
+ if (opts.minimumIdle) opts.minimumIdle = parseInt(opts.minimumIdle);
20
+ if (opts.noControlAfterUse) opts.noControlAfterUse = opts.noControlAfterUse == 'true';
21
+ if (opts.resetAfterUse) opts.resetAfterUse = opts.resetAfterUse == 'true';
22
+ if (opts.pingTimeout) opts.pingTimeout = parseInt(opts.pingTimeout);
23
+ }
24
+
25
+ this.acquireTimeout = opts.acquireTimeout === undefined ? 10000 : opts.acquireTimeout;
26
+ this.connectionLimit = opts.connectionLimit === undefined ? 10 : opts.connectionLimit;
27
+ this.idleTimeout = opts.idleTimeout || 1800;
28
+ this.leakDetectionTimeout = opts.leakDetectionTimeout || 0;
29
+ this.initializationTimeout =
30
+ opts.initializationTimeout === undefined ? 30000 : opts.initializationTimeout;
31
+ this.minDelayValidation = opts.minDelayValidation === undefined ? 500 : opts.minDelayValidation;
32
+ this.minimumIdle =
33
+ opts.minimumIdle === undefined
34
+ ? this.connectionLimit
35
+ : Math.min(opts.minimumIdle, this.connectionLimit);
36
+ this.noControlAfterUse = opts.noControlAfterUse || false;
37
+ this.resetAfterUse = opts.resetAfterUse === undefined ? true : opts.resetAfterUse;
38
+ this.pingTimeout = opts.pingTimeout || 250;
39
+ this.connOptions = new ConnOptions(opts);
40
+
41
+ if (this.acquireTimeout > 0 && this.connOptions.connectTimeout > this.acquireTimeout) {
42
+ this.connOptions.connectTimeout = this.acquireTimeout;
43
+ }
44
+ }
45
+ }
46
+
47
+ module.exports = PoolOptions;
@@ -0,0 +1,160 @@
1
+ 'use strict';
2
+
3
+ const Connection = require('./connection');
4
+ const util = require('util');
5
+ const Errors = require('./misc/errors');
6
+ const { Status } = require('./const/connection_status');
7
+
8
+ function ConnectionCallback(options) {
9
+ Connection.call(this, options);
10
+
11
+ let connecting = 1;
12
+ const connectPromise = this.connect.bind(this);
13
+ const changeUserPromise = this.changeUser.bind(this);
14
+ const queryPromise = this.query.bind(this);
15
+ const endPromise = this.end.bind(this);
16
+ const pingPromise = this.ping.bind(this);
17
+ const resetPromise = this.reset.bind(this);
18
+ const commitPromise = this.commit.bind(this);
19
+ const rollbackPromise = this.rollback.bind(this);
20
+
21
+ const emptySuccess = (rows) => {};
22
+ const emptyError = (err) => {};
23
+
24
+ //*****************************************************************
25
+ // internal equivalent with callback of promised functions
26
+ //*****************************************************************
27
+
28
+ const _commitCallback = (callback) => {
29
+ commitPromise()
30
+ .then(() => {
31
+ if (callback) callback(null, null, null);
32
+ })
33
+ .catch(callback || emptyError);
34
+ };
35
+
36
+ const _rollbackCallback = (callback) => {
37
+ rollbackPromise()
38
+ .then(() => {
39
+ if (callback) callback(null, null, null);
40
+ })
41
+ .catch(callback || emptyError);
42
+ };
43
+
44
+ const _pingCallback = (timeout, callback) => {
45
+ let _timeout, _cb;
46
+ if (typeof timeout === 'function') {
47
+ _cb = timeout;
48
+ _timeout = undefined;
49
+ } else {
50
+ _timeout = timeout;
51
+ _cb = callback;
52
+ }
53
+ pingPromise(_timeout)
54
+ .then(_cb || emptySuccess)
55
+ .catch(_cb || emptyError);
56
+ };
57
+
58
+ const _resetCallback = (callback) => {
59
+ resetPromise()
60
+ .then(callback || emptySuccess)
61
+ .catch(callback || emptyError);
62
+ };
63
+
64
+ const _beginTransactionCallback = (callback) => {
65
+ queryPromise('START TRANSACTION')
66
+ .then(() => {
67
+ if (callback) callback(null, null, null);
68
+ })
69
+ .catch(callback || emptyError);
70
+ };
71
+
72
+ const _endCallback = (callback) => {
73
+ endPromise()
74
+ .then(callback || emptySuccess)
75
+ .catch(callback || emptyError);
76
+ };
77
+
78
+ const _connectCallback = function (callback) {
79
+ if (!callback) {
80
+ throw new Errors.createError(
81
+ 'missing callback parameter',
82
+ null,
83
+ false,
84
+ this.info,
85
+ 'HY000',
86
+ Errors.ER_MISSING_PARAMETER
87
+ );
88
+ }
89
+
90
+ if (connecting === 1) {
91
+ this.on('connect', callback);
92
+ } else {
93
+ switch (this._status()) {
94
+ case Status.CLOSING:
95
+ case Status.CLOSED:
96
+ callback(
97
+ Errors.createError(
98
+ 'Connection closed',
99
+ null,
100
+ true,
101
+ this.info,
102
+ '08S01',
103
+ Errors.ER_CONNECTION_ALREADY_CLOSED
104
+ )
105
+ );
106
+ break;
107
+
108
+ default:
109
+ callback();
110
+ }
111
+ }
112
+ };
113
+
114
+ const _changeUserCallback = (options, callback) => {
115
+ let _options, _cb;
116
+ if (typeof options === 'function') {
117
+ _cb = options;
118
+ _options = undefined;
119
+ } else {
120
+ _options = options;
121
+ _cb = callback;
122
+ }
123
+
124
+ changeUserPromise(_options)
125
+ .then(() => {
126
+ if (_cb) _cb(null, null, null);
127
+ })
128
+ .catch(_cb || emptyError);
129
+ };
130
+
131
+ //*****************************************************************
132
+ // replacing public promise function with callback equivalent
133
+ //*****************************************************************
134
+
135
+ this.commit = _commitCallback;
136
+ this.rollback = _rollbackCallback;
137
+ this.ping = _pingCallback;
138
+ this.reset = _resetCallback;
139
+ this.end = _endCallback;
140
+ this.connect = _connectCallback;
141
+ this.changeUser = _changeUserCallback;
142
+ this.query = this._queryCallback;
143
+ this.batch = this._batchCallback;
144
+ this.beginTransaction = _beginTransactionCallback;
145
+
146
+ const self = this;
147
+ connectPromise()
148
+ .then(() => {
149
+ connecting = 0;
150
+ self.emit('connect');
151
+ })
152
+ .catch((err) => {
153
+ connecting = 0;
154
+ self.emit('connect', err);
155
+ });
156
+ }
157
+
158
+ util.inherits(ConnectionCallback, Connection);
159
+
160
+ module.exports = ConnectionCallback;