@e-mc/db 0.7.0 → 0.7.2

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,11 @@
1
- Copyright 2023 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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
-
1
+ Copyright 2023 Wit Studio
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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
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.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
- ### @e-mc/db
1
+ # @e-mc/db
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Mikasa
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { DbConstructor } from '../types/lib';
2
-
3
- declare const Db: DbConstructor;
4
-
1
+ import type { DbConstructor } from '../types/lib';
2
+
3
+ declare const Db: DbConstructor;
4
+
5
5
  export = Db;
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
- const types_1 = require("../types");
5
- const core_1 = require("../core");
6
- const request_1 = require("../request");
7
- const util_1 = require("./util");
4
+ const types_1 = require("@e-mc/types");
5
+ const core_1 = require("@e-mc/core");
6
+ const request_1 = require("@e-mc/request");
7
+ 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) {
@@ -62,12 +62,12 @@ class Db extends core_1.ClientDb {
62
62
  static getPoolConfig(source) {
63
63
  return POOL_CONFIG.get(source);
64
64
  }
65
- setCredential(item) {
65
+ async setCredential(item) {
66
66
  try {
67
67
  return this.getClient(item.source).setCredential.call(this, item);
68
68
  }
69
69
  catch (err) {
70
- return Promise.reject(err instanceof Error ? err : new Error(Db.asString(err) || "Invalid credentials" /* ERR_DB.CREDENTIALS */));
70
+ return Promise.reject(err instanceof Error ? err : new Error(Db.asString(err) || "Invalid credentials"));
71
71
  }
72
72
  }
73
73
  getCredential(item) {
@@ -93,7 +93,7 @@ class Db extends core_1.ClientDb {
93
93
  return false;
94
94
  }
95
95
  }
96
- executeQuery(item, options) {
96
+ async executeQuery(item, options) {
97
97
  if (this.aborted) {
98
98
  return Promise.reject((0, types_1.createAbortError)());
99
99
  }
@@ -104,7 +104,7 @@ class Db extends core_1.ClientDb {
104
104
  return Promise.reject(err);
105
105
  }
106
106
  }
107
- executeBatchQuery(batch, options, outResult) {
107
+ async executeBatchQuery(batch, options, outResult) {
108
108
  if (this.aborted) {
109
109
  return Promise.reject((0, types_1.createAbortError)());
110
110
  }
@@ -115,13 +115,13 @@ class Db extends core_1.ClientDb {
115
115
  return Promise.reject(err);
116
116
  }
117
117
  }
118
- processRows(batch, tasks, parallel, outResult) {
118
+ async processRows(batch, tasks, parallel, outResult) {
119
119
  let disconnect;
120
120
  if ((0, types_1.isObject)(parallel)) {
121
121
  ({ disconnect, parallel } = parallel);
122
122
  }
123
123
  const terminate = () => {
124
- this.applyState(batch, 8 /* DB_TRANSACTION.TERMINATE */);
124
+ this.applyState(batch, 8);
125
125
  if (typeof disconnect === 'function') {
126
126
  try {
127
127
  disconnect();
@@ -131,7 +131,7 @@ class Db extends core_1.ClientDb {
131
131
  }
132
132
  };
133
133
  const cleanup = () => {
134
- this.applyState(batch, 16 /* DB_TRANSACTION.ABORT */);
134
+ this.applyState(batch, 16);
135
135
  terminate();
136
136
  if (outResult) {
137
137
  for (let i = 0, length = outResult.length; i < length; ++i) {
@@ -162,7 +162,7 @@ class Db extends core_1.ClientDb {
162
162
  .catch(() => cleanup());
163
163
  }
164
164
  handleFail(err, item, options) {
165
- this.add(item, 32 /* DB_TRANSACTION.FAIL */);
165
+ this.add(item, 32);
166
166
  item.transactionFail = true;
167
167
  if (options && typeof options.errorQuery === 'function') {
168
168
  if (options.errorQuery(err, item, options.commandType)) {
@@ -176,7 +176,7 @@ class Db extends core_1.ClientDb {
176
176
  if (item.willAbort) {
177
177
  this.abort();
178
178
  }
179
- this.writeFail(["Unable to execute query" /* ERR_DB.EXEC_QUERY */, item.source], err, 65536 /* LOG_TYPE.DB */);
179
+ this.writeFail(["Unable to execute query", item.source], err, 65536);
180
180
  }
181
181
  return false;
182
182
  }
@@ -184,14 +184,14 @@ class Db extends core_1.ClientDb {
184
184
  if (this.aborted) {
185
185
  return Promise.reject((0, types_1.createAbortError)());
186
186
  }
187
- const tasks = (items || this.pending).map(data => {
187
+ const tasks = (items || this.pending).map(async (data) => {
188
188
  data.ignoreCache ?? (data.ignoreCache = true);
189
189
  return this.executeQuery(data).catch(() => {
190
- this.applyState([data], 16 /* DB_TRANSACTION.ABORT */);
190
+ this.applyState([data], 16);
191
191
  return [];
192
192
  });
193
193
  });
194
- return tasks.length === 0 ? Promise.resolve(false) : this.allSettled(tasks, ["Execute unassigned queries" /* VAL_DB.EXEC_QUERYUNASSIGNED */, this.moduleName]).then(result => result.length > 0).catch(() => false);
194
+ return tasks.length === 0 ? Promise.resolve(false) : this.allSettled(tasks, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
195
195
  }
196
196
  readTLSCert(value, cache) {
197
197
  if ((0, types_1.isString)(value)) {
@@ -226,10 +226,10 @@ class Db extends core_1.ClientDb {
226
226
  }
227
227
  resolveSource(source, folder) {
228
228
  let result;
229
- if (source[0] !== '@') {
229
+ if (!source.startsWith('@')) {
230
230
  result = this.settings.imports?.[source] || util_1.IMPORTS[source];
231
231
  }
232
- else if (!folder && source.indexOf('/') === -1) {
232
+ else if (!folder && !source.includes('/')) {
233
233
  folder = 'client';
234
234
  }
235
235
  return (result || source) + (folder ? '/' + folder : '');
@@ -273,11 +273,11 @@ class Db extends core_1.ClientDb {
273
273
  }
274
274
  catch {
275
275
  }
276
- throw (0, types_1.errorMessage)(source, "Database provider not found" /* ERR_DB.PROVIDER_NOTFOUND */);
276
+ throw (0, types_1.errorMessage)(source, "Database provider not found");
277
277
  }
278
278
  }
279
- Db.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.DB_PARTITION_SIZE */;
280
- Db.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.DB_PARTITION_MULT */;
279
+ Db.STORE_RESULT_PARTITION_SIZE = 16;
280
+ Db.STORE_RESULT_PARTITION_MULT = 2;
281
281
  Object.freeze(types_1.DB_TYPE);
282
282
  Object.freeze(util_1.SQL_COMMAND);
283
283
  exports.default = Db;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/e-mc.git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
13
  "directory": "src/db"
14
14
  },
15
15
  "keywords": [
@@ -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.7.0",
24
- "@e-mc/request": "0.7.0",
25
- "@e-mc/types": "0.7.0"
23
+ "@e-mc/core": "0.7.2",
24
+ "@e-mc/request": "0.7.2",
25
+ "@e-mc/types": "0.7.2"
26
26
  }
27
27
  }
package/pool.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { DbPoolConstructor } from '../types/lib/db';
2
-
3
- declare const DbPool: DbPoolConstructor;
4
-
1
+ import type { DbPoolConstructor } from '../types/lib/db';
2
+
3
+ declare const DbPool: DbPoolConstructor;
4
+
5
5
  export = DbPool;
package/pool.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  var _a, _b, _c;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const types_1 = require("../types");
5
- const util_1 = require("./util");
4
+ const types_1 = require("@e-mc/types");
5
+ const util_1 = require("@e-mc/db/util");
6
6
  const kItems = Symbol('items');
7
7
  const kParent = Symbol('parent');
8
8
  const kIdlePrevious = Symbol('idlePrevious');
@@ -88,7 +88,7 @@ class DbPool {
88
88
  delete parent[this.poolKey];
89
89
  }
90
90
  }
91
- detach(force) {
91
+ async detach(force) {
92
92
  this.remove();
93
93
  return this.closed ? Promise.resolve() : force ? this.close().catch(() => { }) : this.close();
94
94
  }
@@ -113,7 +113,7 @@ class DbPool {
113
113
  }
114
114
  previous.success = success;
115
115
  previous.failed = failed;
116
- return Date.now() - timeout >= this.lastAccessed && (this.closeable || count >= (this.uuidKey ? 10 /* IDLE_THRESHOLD.UUID */ : 5 /* IDLE_THRESHOLD.CONFIG */)) || error >= (this.uuidKey ? 3 /* IDLE_THRESHOLD.UUID_ERROR */ : 2 /* IDLE_THRESHOLD.CONFIG_ERROR */);
116
+ return Date.now() - timeout >= this.lastAccessed && (this.closeable || count >= (this.uuidKey ? 10 : 5)) || error >= (this.uuidKey ? 3 : 2);
117
117
  }
118
118
  get persist() {
119
119
  return this.uuidKey ? this.success > this.failed : false;
package/util.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasBasicAuth = exports.getBasicAuth = exports.setUUIDKey = exports.checkEmpty = exports.parseConnectionString = exports.parseServerAuth = exports.IMPORTS = exports.SQL_COMMAND = void 0;
4
- const types_1 = require("../types");
5
- const util_1 = require("../request/util");
4
+ const types_1 = require("@e-mc/types");
5
+ const util_1 = require("@e-mc/request/util");
6
6
  Object.defineProperty(exports, "getBasicAuth", { enumerable: true, get: function () { return util_1.getBasicAuth; } });
7
7
  Object.defineProperty(exports, "hasBasicAuth", { enumerable: true, get: function () { return util_1.hasBasicAuth; } });
8
8
  var SQL_COMMAND;