orcaq 1.0.21 → 1.0.23

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 (211) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/{CrgoNCm2.js → 0fpkWcbi.js} +2 -2
  3. package/.output/public/_nuxt/{DL3T5jYo.js → B6lwWVI5.js} +1 -1
  4. package/.output/public/_nuxt/BGEWnlhd.js +1 -0
  5. package/.output/public/_nuxt/BUePl0lK.js +1 -0
  6. package/.output/public/_nuxt/BWeOEh4Z.js +14 -0
  7. package/.output/public/_nuxt/BXECqniz.js +1 -0
  8. package/.output/public/_nuxt/BYa7Vkmx.js +1 -0
  9. package/.output/public/_nuxt/BeC_ewNB.js +47 -0
  10. package/.output/public/_nuxt/BeL_GfX-.js +39 -0
  11. package/.output/public/_nuxt/{CuBKbBH_.js → BkhEpKzy.js} +1 -1
  12. package/.output/public/_nuxt/{BH83_dXo.js → C26aAkUg.js} +1 -1
  13. package/.output/public/_nuxt/C81RYsqJ.js +26 -0
  14. package/.output/public/_nuxt/CFtLQlpa.js +1 -0
  15. package/.output/public/_nuxt/CHae0Jiv.js +1 -0
  16. package/.output/public/_nuxt/{9lJACZIQ.js → CJER2x4r.js} +1 -1
  17. package/.output/public/_nuxt/{ICwM1E4-.js → CYqdSIe6.js} +3 -3
  18. package/.output/public/_nuxt/CcN517Ci.js +1 -0
  19. package/.output/public/_nuxt/CfqyI4g1.js +4 -0
  20. package/.output/public/_nuxt/CnIhd9IM.js +9 -0
  21. package/.output/public/_nuxt/Co87DPdr.js +18 -0
  22. package/.output/public/_nuxt/{pAheHeBV.js → CouqeYue.js} +8 -8
  23. package/.output/public/_nuxt/Cv3wRRZy.js +31 -0
  24. package/.output/public/_nuxt/{DXV2HFBA.js → CvXDjqNF.js} +1 -1
  25. package/.output/public/_nuxt/D0LmHvgn.js +13 -0
  26. package/.output/public/_nuxt/{ivUnXl9B.js → D2Hot6Qz.js} +1 -1
  27. package/.output/public/_nuxt/D5XzVg8o.js +1 -0
  28. package/.output/public/_nuxt/{Bq3cyzOD.js → DCGzl5t1.js} +1 -1
  29. package/.output/public/_nuxt/DGE1UZv7.js +1 -0
  30. package/.output/public/_nuxt/{BNjPC06x.js → DNVnfTwM.js} +1 -1
  31. package/.output/public/_nuxt/DV-vuGJt.js +1 -0
  32. package/.output/public/_nuxt/DVwaLKvw.js +5 -0
  33. package/.output/public/_nuxt/{C2HlI1ss.js → DcIs4zDC.js} +1 -1
  34. package/.output/public/_nuxt/{Bh6RgYlO.js → DcoZ0u0V.js} +1 -1
  35. package/.output/public/_nuxt/Dduxqd2M.js +1 -0
  36. package/.output/public/_nuxt/DroUt-ok.js +1 -0
  37. package/.output/public/_nuxt/{D8vj6kFe.js → DyUmhpWC.js} +11 -11
  38. package/.output/public/_nuxt/JGp8ZHkv.js +257 -0
  39. package/.output/public/_nuxt/KoN09pZ5.js +1 -0
  40. package/.output/public/_nuxt/builds/latest.json +1 -1
  41. package/.output/public/_nuxt/builds/meta/bbd2d18d-c265-48d2-a51b-1d563b817934.json +1 -0
  42. package/.output/public/_nuxt/cX_8SODe.js +1 -0
  43. package/.output/public/_nuxt/entry.SsrkN9_U.css +1 -0
  44. package/.output/public/_nuxt/{C25Tmn1m.js → jEcGO2vg.js} +1 -1
  45. package/.output/public/_nuxt/vt077W6w.js +1 -0
  46. package/.output/public/_nuxt/yruHU3cQ.js +1 -0
  47. package/.output/public/_nuxt/zeVrAOTr.js +8 -0
  48. package/.output/server/chunks/build/client.manifest.mjs +305 -296
  49. package/.output/server/chunks/build/client.manifest.mjs.map +1 -1
  50. package/.output/server/chunks/nitro/nitro.mjs +255 -241
  51. package/.output/server/node_modules/aws-ssl-profiles/lib/index.js +13 -0
  52. package/.output/server/node_modules/aws-ssl-profiles/lib/profiles/ca/defaults.js +2888 -0
  53. package/.output/server/node_modules/aws-ssl-profiles/lib/profiles/ca/proxies.js +111 -0
  54. package/.output/server/node_modules/aws-ssl-profiles/package.json +52 -0
  55. package/.output/server/node_modules/generate-function/index.js +181 -0
  56. package/.output/server/node_modules/generate-function/package.json +32 -0
  57. package/.output/server/node_modules/iconv-lite/encodings/dbcs-codec.js +597 -0
  58. package/.output/server/node_modules/iconv-lite/encodings/dbcs-data.js +188 -0
  59. package/.output/server/node_modules/iconv-lite/encodings/index.js +23 -0
  60. package/.output/server/node_modules/iconv-lite/encodings/internal.js +198 -0
  61. package/.output/server/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
  62. package/.output/server/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  63. package/.output/server/node_modules/iconv-lite/encodings/sbcs-data.js +179 -0
  64. package/.output/server/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  65. package/.output/server/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  66. package/.output/server/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  67. package/.output/server/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  68. package/.output/server/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  69. package/.output/server/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  70. package/.output/server/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
  71. package/.output/server/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  72. package/.output/server/node_modules/iconv-lite/encodings/utf16.js +197 -0
  73. package/.output/server/node_modules/iconv-lite/encodings/utf32.js +319 -0
  74. package/.output/server/node_modules/iconv-lite/encodings/utf7.js +290 -0
  75. package/.output/server/node_modules/iconv-lite/lib/bom-handling.js +52 -0
  76. package/.output/server/node_modules/iconv-lite/lib/index.js +180 -0
  77. package/.output/server/node_modules/iconv-lite/lib/streams.js +109 -0
  78. package/.output/server/node_modules/iconv-lite/package.json +44 -0
  79. package/.output/server/node_modules/is-property/is-property.js +5 -0
  80. package/.output/server/node_modules/is-property/package.json +36 -0
  81. package/.output/server/node_modules/long/package.json +58 -0
  82. package/.output/server/node_modules/long/umd/index.js +1622 -0
  83. package/.output/server/node_modules/long/umd/package.json +3 -0
  84. package/.output/server/node_modules/lru.min/lib/index.js +231 -0
  85. package/.output/server/node_modules/lru.min/package.json +87 -0
  86. package/.output/server/node_modules/mysql2/index.js +77 -0
  87. package/.output/server/node_modules/mysql2/lib/auth_41.js +95 -0
  88. package/.output/server/node_modules/mysql2/lib/auth_plugins/caching_sha2_password.js +108 -0
  89. package/.output/server/node_modules/mysql2/lib/auth_plugins/index.js +8 -0
  90. package/.output/server/node_modules/mysql2/lib/auth_plugins/mysql_clear_password.js +17 -0
  91. package/.output/server/node_modules/mysql2/lib/auth_plugins/mysql_native_password.js +34 -0
  92. package/.output/server/node_modules/mysql2/lib/auth_plugins/sha256_password.js +68 -0
  93. package/.output/server/node_modules/mysql2/lib/base/connection.js +978 -0
  94. package/.output/server/node_modules/mysql2/lib/base/pool.js +237 -0
  95. package/.output/server/node_modules/mysql2/lib/base/pool_connection.js +70 -0
  96. package/.output/server/node_modules/mysql2/lib/commands/auth_switch.js +111 -0
  97. package/.output/server/node_modules/mysql2/lib/commands/binlog_dump.js +109 -0
  98. package/.output/server/node_modules/mysql2/lib/commands/change_user.js +68 -0
  99. package/.output/server/node_modules/mysql2/lib/commands/client_handshake.js +241 -0
  100. package/.output/server/node_modules/mysql2/lib/commands/close_statement.js +18 -0
  101. package/.output/server/node_modules/mysql2/lib/commands/command.js +54 -0
  102. package/.output/server/node_modules/mysql2/lib/commands/execute.js +112 -0
  103. package/.output/server/node_modules/mysql2/lib/commands/index.js +27 -0
  104. package/.output/server/node_modules/mysql2/lib/commands/ping.js +36 -0
  105. package/.output/server/node_modules/mysql2/lib/commands/prepare.js +143 -0
  106. package/.output/server/node_modules/mysql2/lib/commands/query.js +366 -0
  107. package/.output/server/node_modules/mysql2/lib/commands/quit.js +29 -0
  108. package/.output/server/node_modules/mysql2/lib/commands/register_slave.js +27 -0
  109. package/.output/server/node_modules/mysql2/lib/commands/server_handshake.js +203 -0
  110. package/.output/server/node_modules/mysql2/lib/compressed_protocol.js +127 -0
  111. package/.output/server/node_modules/mysql2/lib/connection.js +12 -0
  112. package/.output/server/node_modules/mysql2/lib/connection_config.js +294 -0
  113. package/.output/server/node_modules/mysql2/lib/constants/charset_encodings.js +316 -0
  114. package/.output/server/node_modules/mysql2/lib/constants/charsets.js +317 -0
  115. package/.output/server/node_modules/mysql2/lib/constants/client.js +39 -0
  116. package/.output/server/node_modules/mysql2/lib/constants/commands.js +36 -0
  117. package/.output/server/node_modules/mysql2/lib/constants/cursor.js +8 -0
  118. package/.output/server/node_modules/mysql2/lib/constants/encoding_charset.js +50 -0
  119. package/.output/server/node_modules/mysql2/lib/constants/errors.js +3973 -0
  120. package/.output/server/node_modules/mysql2/lib/constants/field_flags.js +20 -0
  121. package/.output/server/node_modules/mysql2/lib/constants/server_status.js +44 -0
  122. package/.output/server/node_modules/mysql2/lib/constants/session_track.js +11 -0
  123. package/.output/server/node_modules/mysql2/lib/constants/ssl_profiles.js +11 -0
  124. package/.output/server/node_modules/mysql2/lib/constants/types.js +64 -0
  125. package/.output/server/node_modules/mysql2/lib/create_connection.js +10 -0
  126. package/.output/server/node_modules/mysql2/lib/create_pool.js +10 -0
  127. package/.output/server/node_modules/mysql2/lib/create_pool_cluster.js +9 -0
  128. package/.output/server/node_modules/mysql2/lib/helpers.js +86 -0
  129. package/.output/server/node_modules/mysql2/lib/packet_parser.js +195 -0
  130. package/.output/server/node_modules/mysql2/lib/packets/auth_next_factor.js +35 -0
  131. package/.output/server/node_modules/mysql2/lib/packets/auth_switch_request.js +38 -0
  132. package/.output/server/node_modules/mysql2/lib/packets/auth_switch_request_more_data.js +33 -0
  133. package/.output/server/node_modules/mysql2/lib/packets/auth_switch_response.js +30 -0
  134. package/.output/server/node_modules/mysql2/lib/packets/binary_row.js +95 -0
  135. package/.output/server/node_modules/mysql2/lib/packets/binlog_dump.js +33 -0
  136. package/.output/server/node_modules/mysql2/lib/packets/binlog_query_statusvars.js +115 -0
  137. package/.output/server/node_modules/mysql2/lib/packets/change_user.js +97 -0
  138. package/.output/server/node_modules/mysql2/lib/packets/close_statement.js +21 -0
  139. package/.output/server/node_modules/mysql2/lib/packets/column_definition.js +291 -0
  140. package/.output/server/node_modules/mysql2/lib/packets/execute.js +214 -0
  141. package/.output/server/node_modules/mysql2/lib/packets/handshake.js +112 -0
  142. package/.output/server/node_modules/mysql2/lib/packets/handshake_response.js +144 -0
  143. package/.output/server/node_modules/mysql2/lib/packets/index.js +152 -0
  144. package/.output/server/node_modules/mysql2/lib/packets/packet.js +931 -0
  145. package/.output/server/node_modules/mysql2/lib/packets/prepare_statement.js +27 -0
  146. package/.output/server/node_modules/mysql2/lib/packets/prepared_statement_header.js +16 -0
  147. package/.output/server/node_modules/mysql2/lib/packets/query.js +27 -0
  148. package/.output/server/node_modules/mysql2/lib/packets/register_slave.js +46 -0
  149. package/.output/server/node_modules/mysql2/lib/packets/resultset_header.js +124 -0
  150. package/.output/server/node_modules/mysql2/lib/packets/ssl_request.js +25 -0
  151. package/.output/server/node_modules/mysql2/lib/packets/text_row.js +47 -0
  152. package/.output/server/node_modules/mysql2/lib/parsers/binary_parser.js +235 -0
  153. package/.output/server/node_modules/mysql2/lib/parsers/parser_cache.js +68 -0
  154. package/.output/server/node_modules/mysql2/lib/parsers/static_binary_parser.js +213 -0
  155. package/.output/server/node_modules/mysql2/lib/parsers/static_text_parser.js +152 -0
  156. package/.output/server/node_modules/mysql2/lib/parsers/string.js +50 -0
  157. package/.output/server/node_modules/mysql2/lib/parsers/text_parser.js +214 -0
  158. package/.output/server/node_modules/mysql2/lib/pool.js +12 -0
  159. package/.output/server/node_modules/mysql2/lib/pool_cluster.js +369 -0
  160. package/.output/server/node_modules/mysql2/lib/pool_config.js +30 -0
  161. package/.output/server/node_modules/mysql2/lib/pool_connection.js +12 -0
  162. package/.output/server/node_modules/mysql2/lib/promise/connection.js +222 -0
  163. package/.output/server/node_modules/mysql2/lib/promise/inherit_events.js +27 -0
  164. package/.output/server/node_modules/mysql2/lib/promise/make_done_cb.js +19 -0
  165. package/.output/server/node_modules/mysql2/lib/promise/pool.js +112 -0
  166. package/.output/server/node_modules/mysql2/lib/promise/pool_cluster.js +54 -0
  167. package/.output/server/node_modules/mysql2/lib/promise/pool_connection.js +19 -0
  168. package/.output/server/node_modules/mysql2/lib/promise/prepared_statement_info.js +32 -0
  169. package/.output/server/node_modules/mysql2/lib/server.js +37 -0
  170. package/.output/server/node_modules/mysql2/package.json +80 -0
  171. package/.output/server/node_modules/mysql2/promise.js +202 -0
  172. package/.output/server/node_modules/named-placeholders/index.js +179 -0
  173. package/.output/server/node_modules/named-placeholders/package.json +36 -0
  174. package/.output/server/node_modules/safer-buffer/package.json +34 -0
  175. package/.output/server/node_modules/safer-buffer/safer.js +77 -0
  176. package/.output/server/node_modules/seq-queue/index.js +1 -0
  177. package/.output/server/node_modules/seq-queue/lib/seq-queue.js +199 -0
  178. package/.output/server/node_modules/seq-queue/package.json +16 -0
  179. package/.output/server/node_modules/sqlstring/index.js +1 -0
  180. package/.output/server/node_modules/sqlstring/lib/SqlString.js +237 -0
  181. package/.output/server/node_modules/sqlstring/package.json +47 -0
  182. package/.output/server/package.json +12 -1
  183. package/package.json +1 -1
  184. package/.output/public/_nuxt/8qASMGdV.js +0 -1
  185. package/.output/public/_nuxt/B2DnNiWd.js +0 -1
  186. package/.output/public/_nuxt/BIKqrFbQ.js +0 -1
  187. package/.output/public/_nuxt/BPQ-Pz1w.js +0 -39
  188. package/.output/public/_nuxt/BRpgKkVT.js +0 -51
  189. package/.output/public/_nuxt/BTCLPbPY.js +0 -4
  190. package/.output/public/_nuxt/BUV-RarV.js +0 -1
  191. package/.output/public/_nuxt/Bt9sU68B.js +0 -9
  192. package/.output/public/_nuxt/BwpH2ZxJ.js +0 -1
  193. package/.output/public/_nuxt/CU3ZV9iV.js +0 -1
  194. package/.output/public/_nuxt/CbcyysXi.js +0 -1
  195. package/.output/public/_nuxt/CepyvMhE.js +0 -1
  196. package/.output/public/_nuxt/CulD8qYQ.js +0 -193
  197. package/.output/public/_nuxt/CylkLpwm.js +0 -1
  198. package/.output/public/_nuxt/D-bWLYHw.js +0 -1
  199. package/.output/public/_nuxt/D-zecHND.js +0 -1
  200. package/.output/public/_nuxt/DIETYtCL.js +0 -1
  201. package/.output/public/_nuxt/DJ4vUzxS.js +0 -1
  202. package/.output/public/_nuxt/DK-itzXx.js +0 -8
  203. package/.output/public/_nuxt/Dh2zppOR.js +0 -1
  204. package/.output/public/_nuxt/DlmSeCnw.js +0 -5
  205. package/.output/public/_nuxt/DswTpYG4.js +0 -1
  206. package/.output/public/_nuxt/G830WtVn.js +0 -1
  207. package/.output/public/_nuxt/QZbJy9YW.js +0 -31
  208. package/.output/public/_nuxt/UXhX8z2W.js +0 -1
  209. package/.output/public/_nuxt/builds/meta/03cede5c-c45c-41b3-ac1a-73756bb8cff0.json +0 -1
  210. package/.output/public/_nuxt/entry.GqPNPe1e.css +0 -1
  211. package/.output/public/_nuxt/s5fCn4j5.js +0 -1
@@ -0,0 +1,369 @@
1
+ 'use strict';
2
+
3
+ const process = require('process');
4
+
5
+ const Pool = require('./pool.js');
6
+ const PoolConfig = require('./pool_config.js');
7
+ const Connection = require('./connection.js');
8
+ const EventEmitter = require('events').EventEmitter;
9
+
10
+ /**
11
+ * Selector
12
+ */
13
+ const makeSelector = {
14
+ RR() {
15
+ let index = 0;
16
+ return (clusterIds) => clusterIds[index++ % clusterIds.length];
17
+ },
18
+ RANDOM() {
19
+ return (clusterIds) =>
20
+ clusterIds[Math.floor(Math.random() * clusterIds.length)];
21
+ },
22
+ ORDER() {
23
+ return (clusterIds) => clusterIds[0];
24
+ },
25
+ };
26
+
27
+ const getMonotonicMilliseconds = function () {
28
+ let ms;
29
+
30
+ if (typeof process.hrtime === 'function') {
31
+ ms = process.hrtime();
32
+ ms = ms[0] * 1e3 + ms[1] * 1e-6;
33
+ } else {
34
+ ms = process.uptime() * 1000;
35
+ }
36
+
37
+ return Math.floor(ms);
38
+ };
39
+
40
+ const patternRegExp = function (pattern) {
41
+ if (pattern instanceof RegExp) {
42
+ return pattern;
43
+ }
44
+
45
+ const source = pattern
46
+ .replace(/([.+?^=!:${}()|[\]/\\])/g, '\\$1')
47
+ .replace(/\*/g, '.*');
48
+
49
+ return new RegExp(`^${source}$`);
50
+ };
51
+
52
+ class PoolNamespace {
53
+ constructor(cluster, pattern, selector) {
54
+ this._cluster = cluster;
55
+ this._pattern = pattern;
56
+ this._selector = makeSelector[selector]();
57
+ }
58
+
59
+ getConnection(cb) {
60
+ const clusterNode = this._getClusterNode();
61
+ if (clusterNode === null) {
62
+ let err = new Error('Pool does Not exist.');
63
+ err.code = 'POOL_NOEXIST';
64
+
65
+ if (this._cluster._findNodeIds(this._pattern, true).length !== 0) {
66
+ err = new Error('Pool does Not have online node.');
67
+ err.code = 'POOL_NONEONLINE';
68
+ }
69
+
70
+ return cb(err);
71
+ }
72
+ return this._cluster._getConnection(clusterNode, (err, connection) => {
73
+ if (err) {
74
+ if (
75
+ this._cluster._canRetry &&
76
+ this._cluster._findNodeIds(this._pattern).length !== 0
77
+ ) {
78
+ this._cluster.emit('warn', err);
79
+ return this.getConnection(cb);
80
+ }
81
+
82
+ return cb(err);
83
+ }
84
+ return cb(null, connection);
85
+ });
86
+ }
87
+
88
+ /**
89
+ * pool cluster query
90
+ * @param {*} sql
91
+ * @param {*} values
92
+ * @param {*} cb
93
+ * @returns query
94
+ */
95
+ query(sql, values, cb) {
96
+ const query = Connection.createQuery(sql, values, cb, {});
97
+ this.getConnection((err, conn) => {
98
+ if (err) {
99
+ if (typeof query.onResult === 'function') {
100
+ query.onResult(err);
101
+ } else {
102
+ query.emit('error', err);
103
+ }
104
+ return;
105
+ }
106
+ try {
107
+ conn.query(query).once('end', () => {
108
+ conn.release();
109
+ });
110
+ } catch (e) {
111
+ conn.release();
112
+ throw e;
113
+ }
114
+ });
115
+ return query;
116
+ }
117
+
118
+ /**
119
+ * pool cluster execute
120
+ * @param {*} sql
121
+ * @param {*} values
122
+ * @param {*} cb
123
+ */
124
+ execute(sql, values, cb) {
125
+ if (typeof values === 'function') {
126
+ cb = values;
127
+ values = [];
128
+ }
129
+ this.getConnection((err, conn) => {
130
+ if (err) {
131
+ return cb(err);
132
+ }
133
+ try {
134
+ conn.execute(sql, values, cb).once('end', () => {
135
+ conn.release();
136
+ });
137
+ } catch (e) {
138
+ conn.release();
139
+ throw e;
140
+ }
141
+ });
142
+ }
143
+
144
+ _getClusterNode() {
145
+ const foundNodeIds = this._cluster._findNodeIds(this._pattern);
146
+ if (foundNodeIds.length === 0) {
147
+ return null;
148
+ }
149
+ const nodeId =
150
+ foundNodeIds.length === 1
151
+ ? foundNodeIds[0]
152
+ : this._selector(foundNodeIds);
153
+ return this._cluster._getNode(nodeId);
154
+ }
155
+ }
156
+
157
+ class PoolCluster extends EventEmitter {
158
+ constructor(config) {
159
+ super();
160
+ config = config || {};
161
+ this._canRetry =
162
+ typeof config.canRetry === 'undefined' ? true : config.canRetry;
163
+ this._removeNodeErrorCount = config.removeNodeErrorCount || 5;
164
+ this._restoreNodeTimeout = config.restoreNodeTimeout || 0;
165
+ this._defaultSelector = config.defaultSelector || 'RR';
166
+ this._closed = false;
167
+ this._lastId = 0;
168
+ this._nodes = {};
169
+ this._serviceableNodeIds = [];
170
+ this._namespaces = {};
171
+ this._findCaches = {};
172
+ }
173
+
174
+ of(pattern, selector) {
175
+ pattern = pattern || '*';
176
+ selector = selector || this._defaultSelector;
177
+ selector = selector.toUpperCase();
178
+ if (!makeSelector[selector] === 'undefined') {
179
+ selector = this._defaultSelector;
180
+ }
181
+ const key = pattern + selector;
182
+ if (typeof this._namespaces[key] === 'undefined') {
183
+ this._namespaces[key] = new PoolNamespace(this, pattern, selector);
184
+ }
185
+ return this._namespaces[key];
186
+ }
187
+
188
+ add(id, config) {
189
+ if (typeof id === 'object') {
190
+ config = id;
191
+ id = `CLUSTER::${++this._lastId}`;
192
+ }
193
+ if (typeof this._nodes[id] === 'undefined') {
194
+ this._nodes[id] = {
195
+ id: id,
196
+ errorCount: 0,
197
+ pool: new Pool({ config: new PoolConfig(config) }),
198
+ _offlineUntil: 0,
199
+ };
200
+ this._serviceableNodeIds.push(id);
201
+ this._clearFindCaches();
202
+ }
203
+ }
204
+
205
+ remove(pattern) {
206
+ const foundNodeIds = this._findNodeIds(pattern, true);
207
+
208
+ for (let i = 0; i < foundNodeIds.length; i++) {
209
+ const node = this._getNode(foundNodeIds[i]);
210
+
211
+ if (node) {
212
+ this._removeNode(node);
213
+ }
214
+ }
215
+ }
216
+
217
+ getConnection(pattern, selector, cb) {
218
+ let namespace;
219
+ if (typeof pattern === 'function') {
220
+ cb = pattern;
221
+ namespace = this.of();
222
+ } else {
223
+ if (typeof selector === 'function') {
224
+ cb = selector;
225
+ selector = this._defaultSelector;
226
+ }
227
+ namespace = this.of(pattern, selector);
228
+ }
229
+ namespace.getConnection(cb);
230
+ }
231
+
232
+ end(callback) {
233
+ const cb =
234
+ callback !== undefined
235
+ ? callback
236
+ : (err) => {
237
+ if (err) {
238
+ throw err;
239
+ }
240
+ };
241
+ if (this._closed) {
242
+ process.nextTick(cb);
243
+ return;
244
+ }
245
+
246
+ this._closed = true;
247
+
248
+ let calledBack = false;
249
+ let waitingClose = 0;
250
+ const onEnd = (err) => {
251
+ if (!calledBack && (err || --waitingClose <= 0)) {
252
+ calledBack = true;
253
+ return cb(err);
254
+ }
255
+ };
256
+
257
+ for (const id in this._nodes) {
258
+ waitingClose++;
259
+ this._nodes[id].pool.end(onEnd);
260
+ }
261
+
262
+ if (waitingClose === 0) {
263
+ process.nextTick(onEnd);
264
+ }
265
+ }
266
+
267
+ _findNodeIds(pattern, includeOffline) {
268
+ let currentTime = 0;
269
+ let foundNodeIds = this._findCaches[pattern];
270
+
271
+ if (foundNodeIds === undefined) {
272
+ const expression = patternRegExp(pattern);
273
+
274
+ foundNodeIds = this._serviceableNodeIds.filter((id) =>
275
+ id.match(expression)
276
+ );
277
+ }
278
+
279
+ this._findCaches[pattern] = foundNodeIds;
280
+
281
+ if (includeOffline) {
282
+ return foundNodeIds;
283
+ }
284
+
285
+ return foundNodeIds.filter((nodeId) => {
286
+ const node = this._getNode(nodeId);
287
+
288
+ if (!node._offlineUntil) {
289
+ return true;
290
+ }
291
+
292
+ if (!currentTime) {
293
+ currentTime = getMonotonicMilliseconds();
294
+ }
295
+
296
+ return node._offlineUntil <= currentTime;
297
+ });
298
+ }
299
+
300
+ _getNode(id) {
301
+ return this._nodes[id] || null;
302
+ }
303
+
304
+ _increaseErrorCount(node) {
305
+ const errorCount = ++node.errorCount;
306
+
307
+ if (this._removeNodeErrorCount > errorCount) {
308
+ return;
309
+ }
310
+
311
+ if (this._restoreNodeTimeout > 0) {
312
+ node._offlineUntil =
313
+ getMonotonicMilliseconds() + this._restoreNodeTimeout;
314
+ this.emit('offline', node.id);
315
+ return;
316
+ }
317
+
318
+ this._removeNode(node);
319
+ this.emit('remove', node.id);
320
+ }
321
+
322
+ _decreaseErrorCount(node) {
323
+ let errorCount = node.errorCount;
324
+
325
+ if (errorCount > this._removeNodeErrorCount) {
326
+ errorCount = this._removeNodeErrorCount;
327
+ }
328
+
329
+ if (errorCount < 1) {
330
+ errorCount = 1;
331
+ }
332
+
333
+ node.errorCount = errorCount - 1;
334
+
335
+ if (node._offlineUntil) {
336
+ node._offlineUntil = 0;
337
+ this.emit('online', node.id);
338
+ }
339
+ }
340
+
341
+ _getConnection(node, cb) {
342
+ node.pool.getConnection((err, connection) => {
343
+ if (err) {
344
+ this._increaseErrorCount(node);
345
+ return cb(err);
346
+ }
347
+ this._decreaseErrorCount(node);
348
+
349
+ connection._clusterId = node.id;
350
+ return cb(null, connection);
351
+ });
352
+ }
353
+
354
+ _removeNode(node) {
355
+ const index = this._serviceableNodeIds.indexOf(node.id);
356
+ if (index !== -1) {
357
+ this._serviceableNodeIds.splice(index, 1);
358
+ delete this._nodes[node.id];
359
+ this._clearFindCaches();
360
+ node.pool.end();
361
+ }
362
+ }
363
+
364
+ _clearFindCaches() {
365
+ this._findCaches = {};
366
+ }
367
+ }
368
+
369
+ module.exports = PoolCluster;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const ConnectionConfig = require('./connection_config.js');
4
+
5
+ class PoolConfig {
6
+ constructor(options) {
7
+ if (typeof options === 'string') {
8
+ options = ConnectionConfig.parseUrl(options);
9
+ }
10
+ this.connectionConfig = new ConnectionConfig(options);
11
+ this.waitForConnections =
12
+ options.waitForConnections === undefined
13
+ ? true
14
+ : Boolean(options.waitForConnections);
15
+ this.connectionLimit = isNaN(options.connectionLimit)
16
+ ? 10
17
+ : Number(options.connectionLimit);
18
+ this.maxIdle = isNaN(options.maxIdle)
19
+ ? this.connectionLimit
20
+ : Number(options.maxIdle);
21
+ this.idleTimeout = isNaN(options.idleTimeout)
22
+ ? 60000
23
+ : Number(options.idleTimeout);
24
+ this.queueLimit = isNaN(options.queueLimit)
25
+ ? 0
26
+ : Number(options.queueLimit);
27
+ }
28
+ }
29
+
30
+ module.exports = PoolConfig;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const BasePoolConnection = require('./base/pool_connection.js');
4
+
5
+ class PoolConnection extends BasePoolConnection {
6
+ promise(promiseImpl) {
7
+ const PromisePoolConnection = require('./promise/pool_connection.js');
8
+ return new PromisePoolConnection(this, promiseImpl);
9
+ }
10
+ }
11
+
12
+ module.exports = PoolConnection;
@@ -0,0 +1,222 @@
1
+ 'use strict';
2
+
3
+ const EventEmitter = require('events').EventEmitter;
4
+ const PromisePreparedStatementInfo = require('./prepared_statement_info.js');
5
+ const makeDoneCb = require('./make_done_cb.js');
6
+ const inheritEvents = require('./inherit_events.js');
7
+ const BaseConnection = require('../base/connection.js');
8
+
9
+ class PromiseConnection extends EventEmitter {
10
+ constructor(connection, promiseImpl) {
11
+ super();
12
+ this.connection = connection;
13
+ this.Promise = promiseImpl || Promise;
14
+ inheritEvents(connection, this, [
15
+ 'error',
16
+ 'drain',
17
+ 'connect',
18
+ 'end',
19
+ 'enqueue',
20
+ ]);
21
+ }
22
+
23
+ release() {
24
+ this.connection.release();
25
+ }
26
+
27
+ query(query, params) {
28
+ const c = this.connection;
29
+ const localErr = new Error();
30
+ if (typeof params === 'function') {
31
+ throw new Error(
32
+ 'Callback function is not available with promise clients.'
33
+ );
34
+ }
35
+ return new this.Promise((resolve, reject) => {
36
+ const done = makeDoneCb(resolve, reject, localErr);
37
+ if (params !== undefined) {
38
+ c.query(query, params, done);
39
+ } else {
40
+ c.query(query, done);
41
+ }
42
+ });
43
+ }
44
+
45
+ execute(query, params) {
46
+ const c = this.connection;
47
+ const localErr = new Error();
48
+ if (typeof params === 'function') {
49
+ throw new Error(
50
+ 'Callback function is not available with promise clients.'
51
+ );
52
+ }
53
+ return new this.Promise((resolve, reject) => {
54
+ const done = makeDoneCb(resolve, reject, localErr);
55
+ if (params !== undefined) {
56
+ c.execute(query, params, done);
57
+ } else {
58
+ c.execute(query, done);
59
+ }
60
+ });
61
+ }
62
+
63
+ end() {
64
+ return new this.Promise((resolve) => {
65
+ this.connection.end(resolve);
66
+ });
67
+ }
68
+
69
+ beginTransaction() {
70
+ const c = this.connection;
71
+ const localErr = new Error();
72
+ return new this.Promise((resolve, reject) => {
73
+ const done = makeDoneCb(resolve, reject, localErr);
74
+ c.beginTransaction(done);
75
+ });
76
+ }
77
+
78
+ commit() {
79
+ const c = this.connection;
80
+ const localErr = new Error();
81
+ return new this.Promise((resolve, reject) => {
82
+ const done = makeDoneCb(resolve, reject, localErr);
83
+ c.commit(done);
84
+ });
85
+ }
86
+
87
+ rollback() {
88
+ const c = this.connection;
89
+ const localErr = new Error();
90
+ return new this.Promise((resolve, reject) => {
91
+ const done = makeDoneCb(resolve, reject, localErr);
92
+ c.rollback(done);
93
+ });
94
+ }
95
+
96
+ ping() {
97
+ const c = this.connection;
98
+ const localErr = new Error();
99
+ return new this.Promise((resolve, reject) => {
100
+ c.ping((err) => {
101
+ if (err) {
102
+ localErr.message = err.message;
103
+ localErr.code = err.code;
104
+ localErr.errno = err.errno;
105
+ localErr.sqlState = err.sqlState;
106
+ localErr.sqlMessage = err.sqlMessage;
107
+ reject(localErr);
108
+ } else {
109
+ resolve(true);
110
+ }
111
+ });
112
+ });
113
+ }
114
+
115
+ connect() {
116
+ const c = this.connection;
117
+ const localErr = new Error();
118
+ return new this.Promise((resolve, reject) => {
119
+ c.connect((err, param) => {
120
+ if (err) {
121
+ localErr.message = err.message;
122
+ localErr.code = err.code;
123
+ localErr.errno = err.errno;
124
+ localErr.sqlState = err.sqlState;
125
+ localErr.sqlMessage = err.sqlMessage;
126
+ reject(localErr);
127
+ } else {
128
+ resolve(param);
129
+ }
130
+ });
131
+ });
132
+ }
133
+
134
+ prepare(options) {
135
+ const c = this.connection;
136
+ const promiseImpl = this.Promise;
137
+ const localErr = new Error();
138
+ return new this.Promise((resolve, reject) => {
139
+ c.prepare(options, (err, statement) => {
140
+ if (err) {
141
+ localErr.message = err.message;
142
+ localErr.code = err.code;
143
+ localErr.errno = err.errno;
144
+ localErr.sqlState = err.sqlState;
145
+ localErr.sqlMessage = err.sqlMessage;
146
+ reject(localErr);
147
+ } else {
148
+ const wrappedStatement = new PromisePreparedStatementInfo(
149
+ statement,
150
+ promiseImpl
151
+ );
152
+ resolve(wrappedStatement);
153
+ }
154
+ });
155
+ });
156
+ }
157
+
158
+ changeUser(options) {
159
+ const c = this.connection;
160
+ const localErr = new Error();
161
+ return new this.Promise((resolve, reject) => {
162
+ c.changeUser(options, (err) => {
163
+ if (err) {
164
+ localErr.message = err.message;
165
+ localErr.code = err.code;
166
+ localErr.errno = err.errno;
167
+ localErr.sqlState = err.sqlState;
168
+ localErr.sqlMessage = err.sqlMessage;
169
+ reject(localErr);
170
+ } else {
171
+ resolve();
172
+ }
173
+ });
174
+ });
175
+ }
176
+
177
+ get config() {
178
+ return this.connection.config;
179
+ }
180
+
181
+ get threadId() {
182
+ return this.connection.threadId;
183
+ }
184
+ }
185
+ // patching PromiseConnection
186
+ // create facade functions for prototype functions on "Connection" that are not yet
187
+ // implemented with PromiseConnection
188
+
189
+ // proxy synchronous functions only
190
+ (function (functionsToWrap) {
191
+ for (let i = 0; functionsToWrap && i < functionsToWrap.length; i++) {
192
+ const func = functionsToWrap[i];
193
+
194
+ if (
195
+ typeof BaseConnection.prototype[func] === 'function' &&
196
+ PromiseConnection.prototype[func] === undefined
197
+ ) {
198
+ PromiseConnection.prototype[func] = (function factory(funcName) {
199
+ return function () {
200
+ return BaseConnection.prototype[funcName].apply(
201
+ this.connection,
202
+ arguments
203
+ );
204
+ };
205
+ })(func);
206
+ }
207
+ }
208
+ })([
209
+ // synchronous functions
210
+ 'close',
211
+ 'createBinlogStream',
212
+ 'destroy',
213
+ 'escape',
214
+ 'escapeId',
215
+ 'format',
216
+ 'pause',
217
+ 'pipe',
218
+ 'resume',
219
+ 'unprepare',
220
+ ]);
221
+
222
+ module.exports = PromiseConnection;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ function inheritEvents(source, target, events) {
4
+ const listeners = {};
5
+ target
6
+ .on('newListener', (eventName) => {
7
+ if (events.indexOf(eventName) >= 0 && !target.listenerCount(eventName)) {
8
+ source.on(
9
+ eventName,
10
+ (listeners[eventName] = function () {
11
+ const args = [].slice.call(arguments);
12
+ args.unshift(eventName);
13
+
14
+ target.emit.apply(target, args);
15
+ })
16
+ );
17
+ }
18
+ })
19
+ .on('removeListener', (eventName) => {
20
+ if (events.indexOf(eventName) >= 0 && !target.listenerCount(eventName)) {
21
+ source.removeListener(eventName, listeners[eventName]);
22
+ delete listeners[eventName];
23
+ }
24
+ });
25
+ }
26
+
27
+ module.exports = inheritEvents;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ function makeDoneCb(resolve, reject, localErr) {
4
+ return function (err, rows, fields) {
5
+ if (err) {
6
+ localErr.message = err.message;
7
+ localErr.code = err.code;
8
+ localErr.errno = err.errno;
9
+ localErr.sql = err.sql;
10
+ localErr.sqlState = err.sqlState;
11
+ localErr.sqlMessage = err.sqlMessage;
12
+ reject(localErr);
13
+ } else {
14
+ resolve([rows, fields]);
15
+ }
16
+ };
17
+ }
18
+
19
+ module.exports = makeDoneCb;