@e-mc/db 0.6.2 → 0.6.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.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Ninja Scroll
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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @e-mc/db
2
2
 
3
- PEP 402 - Forever Kagerō
3
+ PEP 402 - Forever Any Mayo
4
4
 
5
5
  ## LICENSE
6
6
 
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 [];
@@ -223,9 +227,10 @@ class Db extends core_1.ClientDb {
223
227
  }
224
228
  }
225
229
  resolveSource(source, folder) {
230
+ var _a;
226
231
  let result;
227
232
  if (!source.startsWith('@')) {
228
- result = this.settings.imports?.[source] || util_1.IMPORTS[source];
233
+ result = ((_a = this.settings.imports) === null || _a === void 0 ? void 0 : _a[source]) || util_1.IMPORTS[source];
229
234
  }
230
235
  else if (!folder && !source.includes('/')) {
231
236
  folder = 'client';
@@ -233,15 +238,16 @@ class Db extends core_1.ClientDb {
233
238
  return (result || source) + (folder ? '/' + folder : '');
234
239
  }
235
240
  getPoolConfig(source, uuidKey) {
241
+ var _a, _b, _c, _d, _e;
236
242
  const config = Db.getPoolConfig(source);
237
243
  const result = uuidKey && this.settingsKey(uuidKey, 'pool');
238
244
  if (result) {
239
245
  if (config) {
240
- result.min ?? (result.min = config.min);
241
- result.max ?? (result.max = config.max);
242
- result.idle ?? (result.idle = config.idle);
243
- result.queue_max ?? (result.queue_max = config.queue_max);
244
- result.queue_idle ?? (result.queue_idle = config.queue_idle);
246
+ (_a = result.min) !== null && _a !== void 0 ? _a : (result.min = config.min);
247
+ (_b = result.max) !== null && _b !== void 0 ? _b : (result.max = config.max);
248
+ (_c = result.idle) !== null && _c !== void 0 ? _c : (result.idle = config.idle);
249
+ (_d = result.queue_max) !== null && _d !== void 0 ? _d : (result.queue_max = config.queue_max);
250
+ (_e = result.queue_idle) !== null && _e !== void 0 ? _e : (result.queue_idle = config.queue_idle);
245
251
  }
246
252
  else {
247
253
  sanitizePoolConfig(result);
@@ -263,7 +269,7 @@ class Db extends core_1.ClientDb {
263
269
  }
264
270
  try {
265
271
  client = require(this.resolveSource(source));
266
- if (client?.DB_SOURCE_CLIENT) {
272
+ if (client === null || client === void 0 ? void 0 : client.DB_SOURCE_CLIENT) {
267
273
  client.DB_SOURCE_NAME = source;
268
274
  DB_CLIENT.set(source, client);
269
275
  return client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.6.2",
3
+ "version": "0.6.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.6.2",
24
- "@e-mc/request": "0.6.2",
25
- "@e-mc/types": "0.6.2"
23
+ "@e-mc/core": "0.6.4",
24
+ "@e-mc/request": "0.6.4",
25
+ "@e-mc/types": "0.6.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;