@e-mc/db 0.5.3 → 0.5.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,11 +1,7 @@
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
-
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.
1
+ Copyright 2023 Mile Square Park
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
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,5 +1,7 @@
1
- ### @e-mc/db
1
+ # @e-mc/db
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever
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) {
@@ -60,12 +60,12 @@ class Db extends core_1.ClientDb {
60
60
  static getPoolConfig(source) {
61
61
  return POOL_CONFIG.get(source);
62
62
  }
63
- setCredential(item) {
63
+ async setCredential(item) {
64
64
  try {
65
65
  return this.getClient(item.source).setCredential.call(this, item);
66
66
  }
67
67
  catch (err) {
68
- return Promise.reject(err instanceof Error ? err : new Error(Db.asString(err) || "Invalid credentials" /* ERR_DB.CREDENTIALS */));
68
+ return Promise.reject(err instanceof Error ? err : new Error(Db.asString(err) || "Invalid credentials"));
69
69
  }
70
70
  }
71
71
  getCredential(item) {
@@ -91,7 +91,7 @@ class Db extends core_1.ClientDb {
91
91
  return false;
92
92
  }
93
93
  }
94
- executeQuery(item, options) {
94
+ async executeQuery(item, options) {
95
95
  if (this.aborted) {
96
96
  return Promise.reject((0, types_1.createAbortError)());
97
97
  }
@@ -102,7 +102,7 @@ class Db extends core_1.ClientDb {
102
102
  return Promise.reject(err);
103
103
  }
104
104
  }
105
- executeBatchQuery(batch, options, outResult) {
105
+ async executeBatchQuery(batch, options, outResult) {
106
106
  if (this.aborted) {
107
107
  return Promise.reject((0, types_1.createAbortError)());
108
108
  }
@@ -113,13 +113,13 @@ class Db extends core_1.ClientDb {
113
113
  return Promise.reject(err);
114
114
  }
115
115
  }
116
- processRows(batch, tasks, parallel, outResult) {
116
+ async processRows(batch, tasks, parallel, outResult) {
117
117
  let disconnect;
118
118
  if ((0, types_1.isObject)(parallel)) {
119
119
  ({ disconnect, parallel } = parallel);
120
120
  }
121
121
  const terminate = () => {
122
- this.applyState(batch, 8 /* DB_TRANSACTION.TERMINATE */);
122
+ this.applyState(batch, 8);
123
123
  if (typeof disconnect === 'function') {
124
124
  try {
125
125
  disconnect();
@@ -129,7 +129,7 @@ class Db extends core_1.ClientDb {
129
129
  }
130
130
  };
131
131
  const cleanup = () => {
132
- this.applyState(batch, 16 /* DB_TRANSACTION.ABORT */);
132
+ this.applyState(batch, 16);
133
133
  terminate();
134
134
  if (outResult) {
135
135
  for (let i = 0, length = outResult.length; i < length; ++i) {
@@ -160,7 +160,7 @@ class Db extends core_1.ClientDb {
160
160
  .catch(() => cleanup());
161
161
  }
162
162
  handleFail(err, item, options) {
163
- this.add(item, 32 /* DB_TRANSACTION.FAIL */);
163
+ this.add(item, 32);
164
164
  item.transactionFail = true;
165
165
  if (options && typeof options.errorQuery === 'function') {
166
166
  if (options.errorQuery(err, item, options.commandType)) {
@@ -174,7 +174,7 @@ class Db extends core_1.ClientDb {
174
174
  if (item.willAbort) {
175
175
  this.abort();
176
176
  }
177
- this.writeFail(["Unable to execute query" /* ERR_DB.EXEC_QUERY */, item.source], err, 65536 /* LOG_TYPE.DB */);
177
+ this.writeFail(["Unable to execute query", item.source], err, 65536);
178
178
  }
179
179
  return false;
180
180
  }
@@ -182,14 +182,14 @@ class Db extends core_1.ClientDb {
182
182
  if (this.aborted) {
183
183
  return Promise.reject((0, types_1.createAbortError)());
184
184
  }
185
- const tasks = (items || this.pending).map(data => {
185
+ const tasks = (items || this.pending).map(async (data) => {
186
186
  data.ignoreCache ?? (data.ignoreCache = true);
187
187
  return this.executeQuery(data).catch(() => {
188
- this.applyState([data], 16 /* DB_TRANSACTION.ABORT */);
188
+ this.applyState([data], 16);
189
189
  return [];
190
190
  });
191
191
  });
192
- 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);
192
+ return tasks.length === 0 ? Promise.resolve(false) : this.allSettled(tasks, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
193
193
  }
194
194
  readTLSCert(value, cache) {
195
195
  if ((0, types_1.isString)(value)) {
@@ -224,7 +224,7 @@ class Db extends core_1.ClientDb {
224
224
  }
225
225
  resolveSource(source, folder) {
226
226
  let result;
227
- if (source[0] !== '@') {
227
+ if (!source.startsWith('@')) {
228
228
  switch (source) {
229
229
  case 'mongodb':
230
230
  case 'mssql':
@@ -239,7 +239,7 @@ class Db extends core_1.ClientDb {
239
239
  break;
240
240
  }
241
241
  }
242
- else if ((result = source).indexOf('/') === -1) {
242
+ else if (!(result = source).includes('/')) {
243
243
  folder || (folder = 'client');
244
244
  }
245
245
  return result + (folder ? '/' + folder : '');
@@ -283,7 +283,7 @@ class Db extends core_1.ClientDb {
283
283
  }
284
284
  catch {
285
285
  }
286
- throw (0, types_1.errorMessage)(source, "Database provider not found" /* ERR_DB.PROVIDER_NOTFOUND */);
286
+ throw (0, types_1.errorMessage)(source, "Database provider not found");
287
287
  }
288
288
  }
289
289
  Object.freeze(types_1.DB_TYPE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
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.5.3",
24
- "@e-mc/request": "0.5.3",
25
- "@e-mc/types": "0.5.3"
23
+ "@e-mc/core": "0.5.4",
24
+ "@e-mc/request": "0.5.4",
25
+ "@e-mc/types": "0.5.4"
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.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;