@e-mc/db 0.6.0 → 0.6.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 +7 -11
- package/README.md +5 -3
- package/index.d.ts +4 -4
- package/index.js +21 -21
- package/package.json +5 -5
- package/pool.d.ts +4 -4
- package/pool.js +4 -4
- package/util.js +2 -2
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright 2023
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 Ninja Scroll
|
|
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
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("
|
|
5
|
-
const core_1 = require("
|
|
6
|
-
const request_1 = require("
|
|
7
|
-
const util_1 = require("
|
|
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"
|
|
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
|
|
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
|
|
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
|
|
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"
|
|
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
|
|
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"
|
|
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,10 +224,10 @@ class Db extends core_1.ClientDb {
|
|
|
224
224
|
}
|
|
225
225
|
resolveSource(source, folder) {
|
|
226
226
|
let result;
|
|
227
|
-
if (source
|
|
227
|
+
if (!source.startsWith('@')) {
|
|
228
228
|
result = this.settings.imports?.[source] || util_1.IMPORTS[source];
|
|
229
229
|
}
|
|
230
|
-
else if (!folder && source.
|
|
230
|
+
else if (!folder && !source.includes('/')) {
|
|
231
231
|
folder = 'client';
|
|
232
232
|
}
|
|
233
233
|
return (result || source) + (folder ? '/' + folder : '');
|
|
@@ -271,11 +271,11 @@ class Db extends core_1.ClientDb {
|
|
|
271
271
|
}
|
|
272
272
|
catch {
|
|
273
273
|
}
|
|
274
|
-
throw (0, types_1.errorMessage)(source, "Database provider not found"
|
|
274
|
+
throw (0, types_1.errorMessage)(source, "Database provider not found");
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
|
-
Db.STORE_RESULT_PARTITION_SIZE = 16
|
|
278
|
-
Db.STORE_RESULT_PARTITION_MULT = 2
|
|
277
|
+
Db.STORE_RESULT_PARTITION_SIZE = 16;
|
|
278
|
+
Db.STORE_RESULT_PARTITION_MULT = 2;
|
|
279
279
|
Object.freeze(types_1.DB_TYPE);
|
|
280
280
|
Object.freeze(util_1.SQL_COMMAND);
|
|
281
281
|
exports.default = Db;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/db",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.6.
|
|
24
|
-
"@e-mc/request": "0.6.
|
|
25
|
-
"@e-mc/types": "0.6.
|
|
23
|
+
"@e-mc/core": "0.6.2",
|
|
24
|
+
"@e-mc/request": "0.6.2",
|
|
25
|
+
"@e-mc/types": "0.6.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("
|
|
5
|
-
const util_1 = require("
|
|
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
|
|
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("
|
|
5
|
-
const util_1 = require("
|
|
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;
|