@e-mc/db 0.8.7 → 0.8.9

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,11 +1,7 @@
1
1
  Copyright 2024 An Pham
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/db
2
2
 
3
3
  * NodeJS 14
4
- * ES2020
4
+ * ES2019
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { DbDataSource } from "./squared";
@@ -94,12 +94,12 @@ interface DbPoolConstructor {
94
94
 
95
95
  ## References
96
96
 
97
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/squared.d.ts
98
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/core.d.ts
99
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/db.d.ts
100
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/object.d.ts
101
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/settings.d.ts
97
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/squared.d.ts
98
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/core.d.ts
99
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/db.d.ts
100
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/object.d.ts
101
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/settings.d.ts
102
102
 
103
103
  ## LICENSE
104
104
 
105
- BSD 3-Clause
105
+ MIT
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, _b;
36
38
  let result = 0;
37
39
  if (percent > 0 && percent <= 1) {
38
40
  for (const [name, client] of DB_CLIENT) {
39
- const purge = POOL_CONFIG.get(name)?.purge || 0;
41
+ const purge = ((_a = POOL_CONFIG.get(name)) === null || _a === void 0 ? void 0 : _a.purge) || 0;
40
42
  if (purge > 0) {
41
- const checkTimeout = client.checkTimeout?.bind(client);
43
+ const checkTimeout = (_b = client.checkTimeout) === null || _b === void 0 ? void 0 : _b.bind(client);
42
44
  if (checkTimeout) {
43
45
  try {
44
46
  result += await checkTimeout(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)) {
@@ -94,6 +97,7 @@ class Db extends core_1.ClientDb {
94
97
  }
95
98
  }
96
99
  applyCommand(...items) {
100
+ var _a, _b, _c;
97
101
  let settings;
98
102
  for (let i = 0, length = items.length; i < length; ++i) {
99
103
  const item = items[i];
@@ -101,12 +105,12 @@ class Db extends core_1.ClientDb {
101
105
  if (!command) {
102
106
  continue;
103
107
  }
104
- if (!settings && !(0, types_1.isPlainObject)(settings = this.getUserSettings()?.[item.source]?.commands)) {
108
+ if (!settings && !(0, types_1.isPlainObject)(settings = (_b = (_a = this.getUserSettings()) === null || _a === void 0 ? void 0 : _a[item.source]) === null || _b === void 0 ? void 0 : _b.commands)) {
105
109
  return;
106
110
  }
107
111
  let name, table;
108
112
  const [group, procedure] = Array.isArray(command) ? command : ({ name, table } = item, [(name || table ? name && table ? name + ':' + table : table || name : typeof item.document === 'string' && item.document) || '', command]);
109
- const data = settings[group]?.[procedure];
113
+ const data = (_c = settings[group]) === null || _c === void 0 ? void 0 : _c[procedure];
110
114
  if (!(0, types_1.isPlainObject)(data)) {
111
115
  continue;
112
116
  }
@@ -214,7 +218,8 @@ class Db extends core_1.ClientDb {
214
218
  return Promise.reject((0, types_1.createAbortError)());
215
219
  }
216
220
  const tasks = (items || this.pending).map(async (data) => {
217
- data.ignoreCache ?? (data.ignoreCache = true);
221
+ var _a;
222
+ (_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
218
223
  return this.executeQuery(data).catch(() => {
219
224
  this.applyState([data], 16);
220
225
  return [];
@@ -254,9 +259,10 @@ class Db extends core_1.ClientDb {
254
259
  }
255
260
  }
256
261
  resolveSource(source, folder) {
262
+ var _a;
257
263
  let result;
258
264
  if (!source.startsWith('@')) {
259
- result = this.settings.imports?.[source] || util_1.IMPORTS[source];
265
+ result = ((_a = this.settings.imports) === null || _a === void 0 ? void 0 : _a[source]) || util_1.IMPORTS[source];
260
266
  }
261
267
  else if (!folder && !source.includes('/')) {
262
268
  folder = 'client';
@@ -264,17 +270,18 @@ class Db extends core_1.ClientDb {
264
270
  return (result || source) + (folder ? '/' + folder : '');
265
271
  }
266
272
  getPoolConfig(source, uuidKey) {
273
+ var _a, _b, _c, _d, _e, _f, _g;
267
274
  const config = Db.getPoolConfig(source);
268
275
  const result = uuidKey && this.settingsKey(uuidKey, 'pool');
269
276
  if (result) {
270
277
  if (config) {
271
- result.min ?? (result.min = config.min);
272
- result.max ?? (result.max = config.max);
273
- result.idle ?? (result.idle = config.idle);
274
- result.queue_max ?? (result.queue_max = config.queue_max);
275
- result.queue_idle ?? (result.queue_idle = config.queue_idle);
276
- result.timeout ?? (result.timeout = config.timeout);
277
- result.socket_timeout ?? (result.socket_timeout = config.socket_timeout);
278
+ (_a = result.min) !== null && _a !== void 0 ? _a : (result.min = config.min);
279
+ (_b = result.max) !== null && _b !== void 0 ? _b : (result.max = config.max);
280
+ (_c = result.idle) !== null && _c !== void 0 ? _c : (result.idle = config.idle);
281
+ (_d = result.queue_max) !== null && _d !== void 0 ? _d : (result.queue_max = config.queue_max);
282
+ (_e = result.queue_idle) !== null && _e !== void 0 ? _e : (result.queue_idle = config.queue_idle);
283
+ (_f = result.timeout) !== null && _f !== void 0 ? _f : (result.timeout = config.timeout);
284
+ (_g = result.socket_timeout) !== null && _g !== void 0 ? _g : (result.socket_timeout = config.socket_timeout);
278
285
  }
279
286
  else {
280
287
  sanitizePoolConfig(result);
@@ -296,7 +303,7 @@ class Db extends core_1.ClientDb {
296
303
  }
297
304
  try {
298
305
  client = require(this.resolveSource(source));
299
- if (client?.DB_SOURCE_CLIENT) {
306
+ if (client === null || client === void 0 ? void 0 : client.DB_SOURCE_CLIENT) {
300
307
  client.DB_SOURCE_NAME = source;
301
308
  DB_CLIENT.set(source, client);
302
309
  return client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,11 +17,11 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.7",
24
- "@e-mc/request": "0.8.7",
25
- "@e-mc/types": "0.8.7"
23
+ "@e-mc/core": "0.8.9",
24
+ "@e-mc/request": "0.8.9",
25
+ "@e-mc/types": "0.8.9"
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;