@e-mc/db 0.7.3 → 0.7.4

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 (4) hide show
  1. package/index.js +24 -18
  2. package/package.json +4 -4
  3. package/pool.js +3 -2
  4. package/util.js +2 -1
package/index.js CHANGED
@@ -8,14 +8,15 @@ const util_1 = require("@e-mc/db/util");
8
8
  const DB_CLIENT = new Map();
9
9
  const POOL_CONFIG = new Map();
10
10
  function sanitizePoolConfig(value) {
11
- value.min ?? (value.min = -1);
12
- value.max ?? (value.max = -1);
13
- value.idle ?? (value.idle = -1);
14
- value.queue_max ?? (value.queue_max = -1);
15
- value.queue_idle ?? (value.queue_idle = -1);
16
- value.purge ?? (value.purge = 0);
17
- value.timeout ?? (value.timeout = -1);
18
- value.socket_timeout ?? (value.socket_timeout = -1);
11
+ var _a, _b, _c, _d, _e, _f, _g, _h;
12
+ (_a = value.min) !== null && _a !== void 0 ? _a : (value.min = -1);
13
+ (_b = value.max) !== null && _b !== void 0 ? _b : (value.max = -1);
14
+ (_c = value.idle) !== null && _c !== void 0 ? _c : (value.idle = -1);
15
+ (_d = value.queue_max) !== null && _d !== void 0 ? _d : (value.queue_max = -1);
16
+ (_e = value.queue_idle) !== null && _e !== void 0 ? _e : (value.queue_idle = -1);
17
+ (_f = value.purge) !== null && _f !== void 0 ? _f : (value.purge = 0);
18
+ (_g = value.timeout) !== null && _g !== void 0 ? _g : (value.timeout = -1);
19
+ (_h = value.socket_timeout) !== null && _h !== void 0 ? _h : (value.socket_timeout = -1);
19
20
  return value;
20
21
  }
21
22
  function setCert(items, cache) {
@@ -33,12 +34,13 @@ class Db extends core_1.ClientDb {
33
34
  this._threadable = true;
34
35
  }
35
36
  static async purgeMemory(percent = 1, limit = 0, parent) {
37
+ var _a;
36
38
  let result = 0;
37
39
  if (percent > 0 && percent <= 1) {
38
40
  for (const [name, client] of DB_CLIENT) {
39
41
  const config = POOL_CONFIG.get(name);
40
42
  if (config && config.purge > 0) {
41
- const checkTimeout = client.checkTimeout?.bind(client);
43
+ const checkTimeout = (_a = client.checkTimeout) === null || _a === void 0 ? void 0 : _a.bind(client);
42
44
  if (checkTimeout) {
43
45
  try {
44
46
  result += await checkTimeout(config.purge, limit);
@@ -71,9 +73,10 @@ class Db extends core_1.ClientDb {
71
73
  }
72
74
  }
73
75
  getCredential(item) {
76
+ var _a;
74
77
  let credential = item.credential, stored;
75
78
  if (typeof credential === 'string') {
76
- credential = this.module[item.source]?.[credential];
79
+ credential = (_a = this.module[item.source]) === null || _a === void 0 ? void 0 : _a[credential];
77
80
  stored = true;
78
81
  }
79
82
  if ((0, types_1.isPlainObject)(credential)) {
@@ -185,7 +188,8 @@ class Db extends core_1.ClientDb {
185
188
  return Promise.reject((0, types_1.createAbortError)());
186
189
  }
187
190
  const tasks = (items || this.pending).map(async (data) => {
188
- data.ignoreCache ?? (data.ignoreCache = true);
191
+ var _a;
192
+ (_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
189
193
  return this.executeQuery(data).catch(() => {
190
194
  this.applyState([data], 16);
191
195
  return [];
@@ -225,9 +229,10 @@ class Db extends core_1.ClientDb {
225
229
  }
226
230
  }
227
231
  resolveSource(source, folder) {
232
+ var _a;
228
233
  let result;
229
234
  if (!source.startsWith('@')) {
230
- result = this.settings.imports?.[source] || util_1.IMPORTS[source];
235
+ result = ((_a = this.settings.imports) === null || _a === void 0 ? void 0 : _a[source]) || util_1.IMPORTS[source];
231
236
  }
232
237
  else if (!folder && !source.includes('/')) {
233
238
  folder = 'client';
@@ -235,15 +240,16 @@ class Db extends core_1.ClientDb {
235
240
  return (result || source) + (folder ? '/' + folder : '');
236
241
  }
237
242
  getPoolConfig(source, uuidKey) {
243
+ var _a, _b, _c, _d, _e;
238
244
  const config = Db.getPoolConfig(source);
239
245
  const result = uuidKey && this.settingsKey(uuidKey, 'pool');
240
246
  if (result) {
241
247
  if (config) {
242
- result.min ?? (result.min = config.min);
243
- result.max ?? (result.max = config.max);
244
- result.idle ?? (result.idle = config.idle);
245
- result.queue_max ?? (result.queue_max = config.queue_max);
246
- result.queue_idle ?? (result.queue_idle = config.queue_idle);
248
+ (_a = result.min) !== null && _a !== void 0 ? _a : (result.min = config.min);
249
+ (_b = result.max) !== null && _b !== void 0 ? _b : (result.max = config.max);
250
+ (_c = result.idle) !== null && _c !== void 0 ? _c : (result.idle = config.idle);
251
+ (_d = result.queue_max) !== null && _d !== void 0 ? _d : (result.queue_max = config.queue_max);
252
+ (_e = result.queue_idle) !== null && _e !== void 0 ? _e : (result.queue_idle = config.queue_idle);
247
253
  }
248
254
  else {
249
255
  sanitizePoolConfig(result);
@@ -265,7 +271,7 @@ class Db extends core_1.ClientDb {
265
271
  }
266
272
  try {
267
273
  client = require(this.resolveSource(source));
268
- if (client?.DB_SOURCE_CLIENT) {
274
+ if (client === null || client === void 0 ? void 0 : client.DB_SOURCE_CLIENT) {
269
275
  client.DB_SOURCE_NAME = source;
270
276
  DB_CLIENT.set(source, client);
271
277
  return client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.7.3",
24
- "@e-mc/request": "0.7.3",
25
- "@e-mc/types": "0.7.3"
23
+ "@e-mc/core": "0.7.4",
24
+ "@e-mc/request": "0.7.4",
25
+ "@e-mc/types": "0.7.4"
26
26
  }
27
27
  }
package/pool.js CHANGED
@@ -34,7 +34,7 @@ class DbPool {
34
34
  for (const key in pools) {
35
35
  const pool = pools[key];
36
36
  const auth = pool.uuidKey;
37
- if (auth?.username === username && auth.password === uuidKey) {
37
+ if ((auth === null || auth === void 0 ? void 0 : auth.username) === username && auth.password === uuidKey) {
38
38
  if (!pool.closed) {
39
39
  return [uuidKey, pool];
40
40
  }
@@ -72,8 +72,9 @@ class DbPool {
72
72
  this[_c] = { success: -1, failed: -1, count: 0, error: 0 };
73
73
  }
74
74
  add(item, uuidKey) {
75
+ var _d;
75
76
  this[kItems].add(item);
76
- if (uuidKey || (uuidKey = this.uuidKey?.password)) {
77
+ if (uuidKey || (uuidKey = (_d = this.uuidKey) === null || _d === void 0 ? void 0 : _d.password)) {
77
78
  (0, util_1.setUUIDKey)(item, uuidKey);
78
79
  }
79
80
  this.lastAccessed = Date.now();
package/util.js CHANGED
@@ -86,13 +86,14 @@ function parseServerAuth(credential, port, all) {
86
86
  }
87
87
  exports.parseServerAuth = parseServerAuth;
88
88
  function parseConnectionString(value, scheme = 'http') {
89
+ var _a;
89
90
  if (!/^[^:]+:\/\//.test(value)) {
90
91
  value = scheme + '://' + value;
91
92
  }
92
93
  try {
93
94
  const { protocol, username, password, hostname, pathname, port, search } = new URL(value);
94
95
  const database = pathname.substring(1);
95
- return { protocol, username: decodeURIComponent(username), password: decodeURIComponent(password), hostname, port, database: decodeURIComponent(/^([^?/#]+)/.exec(database)?.[1] || database), pathname, search };
96
+ return { protocol, username: decodeURIComponent(username), password: decodeURIComponent(password), hostname, port, database: decodeURIComponent(((_a = /^([^?/#]+)/.exec(database)) === null || _a === void 0 ? void 0 : _a[1]) || database), pathname, search };
96
97
  }
97
98
  catch {
98
99
  return null;