@e-mc/db 0.5.4 → 0.5.6

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.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Mile Square Park
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/index.js CHANGED
@@ -8,12 +8,13 @@ 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);
11
+ var _a, _b, _c, _d, _e, _f;
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);
17
18
  return value;
18
19
  }
19
20
  function setCert(items, cache) {
@@ -31,12 +32,13 @@ class Db extends core_1.ClientDb {
31
32
  this._threadable = true;
32
33
  }
33
34
  static async purgeMemory(percent = 1, limit = 0, parent) {
35
+ var _a;
34
36
  let result = 0;
35
37
  if (percent > 0 && percent <= 1) {
36
38
  for (const [name, client] of DB_CLIENT) {
37
39
  const config = POOL_CONFIG.get(name);
38
40
  if (config && config.purge > 0) {
39
- const checkTimeout = client.checkTimeout?.bind(client);
41
+ const checkTimeout = (_a = client.checkTimeout) === null || _a === void 0 ? void 0 : _a.bind(client);
40
42
  if (checkTimeout) {
41
43
  try {
42
44
  result += await checkTimeout(config.purge, limit);
@@ -69,9 +71,10 @@ class Db extends core_1.ClientDb {
69
71
  }
70
72
  }
71
73
  getCredential(item) {
74
+ var _a;
72
75
  let credential = item.credential, stored;
73
76
  if (typeof credential === 'string') {
74
- credential = this.module[item.source]?.[credential];
77
+ credential = (_a = this.module[item.source]) === null || _a === void 0 ? void 0 : _a[credential];
75
78
  stored = true;
76
79
  }
77
80
  if ((0, types_1.isPlainObject)(credential)) {
@@ -183,7 +186,8 @@ class Db extends core_1.ClientDb {
183
186
  return Promise.reject((0, types_1.createAbortError)());
184
187
  }
185
188
  const tasks = (items || this.pending).map(async (data) => {
186
- data.ignoreCache ?? (data.ignoreCache = true);
189
+ var _a;
190
+ (_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
187
191
  return this.executeQuery(data).catch(() => {
188
192
  this.applyState([data], 16);
189
193
  return [];
@@ -226,6 +230,7 @@ class Db extends core_1.ClientDb {
226
230
  let result;
227
231
  if (!source.startsWith('@')) {
228
232
  switch (source) {
233
+ case 'mariadb':
229
234
  case 'mongodb':
230
235
  case 'mssql':
231
236
  case 'mysql':
@@ -245,15 +250,16 @@ class Db extends core_1.ClientDb {
245
250
  return result + (folder ? '/' + folder : '');
246
251
  }
247
252
  getPoolConfig(source, uuidKey) {
253
+ var _a, _b, _c, _d, _e;
248
254
  const config = Db.getPoolConfig(source);
249
255
  const result = uuidKey && this.settingsKey(uuidKey, 'pool');
250
256
  if (result) {
251
257
  if (config) {
252
- result.min ?? (result.min = config.min);
253
- result.max ?? (result.max = config.max);
254
- result.idle ?? (result.idle = config.idle);
255
- result.queue_max ?? (result.queue_max = config.queue_max);
256
- result.queue_idle ?? (result.queue_idle = config.queue_idle);
258
+ (_a = result.min) !== null && _a !== void 0 ? _a : (result.min = config.min);
259
+ (_b = result.max) !== null && _b !== void 0 ? _b : (result.max = config.max);
260
+ (_c = result.idle) !== null && _c !== void 0 ? _c : (result.idle = config.idle);
261
+ (_d = result.queue_max) !== null && _d !== void 0 ? _d : (result.queue_max = config.queue_max);
262
+ (_e = result.queue_idle) !== null && _e !== void 0 ? _e : (result.queue_idle = config.queue_idle);
257
263
  }
258
264
  else {
259
265
  sanitizePoolConfig(result);
@@ -275,7 +281,7 @@ class Db extends core_1.ClientDb {
275
281
  }
276
282
  try {
277
283
  client = require(this.resolveSource(source));
278
- if (client?.DB_SOURCE_CLIENT) {
284
+ if (client === null || client === void 0 ? void 0 : client.DB_SOURCE_CLIENT) {
279
285
  client.DB_SOURCE_NAME = source;
280
286
  DB_CLIENT.set(source, client);
281
287
  return client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
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.5.4",
24
- "@e-mc/request": "0.5.4",
25
- "@e-mc/types": "0.5.4"
23
+ "@e-mc/core": "0.5.6",
24
+ "@e-mc/request": "0.5.6",
25
+ "@e-mc/types": "0.5.6"
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
@@ -77,13 +77,14 @@ function parseServerAuth(credential, port, all) {
77
77
  }
78
78
  exports.parseServerAuth = parseServerAuth;
79
79
  function parseConnectionString(value, scheme = 'http') {
80
+ var _a;
80
81
  if (!/^[^:]+:\/\//.test(value)) {
81
82
  value = scheme + '://' + value;
82
83
  }
83
84
  try {
84
85
  const { protocol, username, password, hostname, pathname, port, search } = new URL(value);
85
86
  const database = pathname.substring(1);
86
- return { protocol, username: decodeURIComponent(username), password: decodeURIComponent(password), hostname, port, database: decodeURIComponent(/^([^?/#]+)/.exec(database)?.[1] || database), pathname, search };
87
+ 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 };
87
88
  }
88
89
  catch {
89
90
  return null;