@e-mc/db 0.8.10 → 0.9.1

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,7 +1,11 @@
1
1
  Copyright 2024 An Pham
2
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:
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
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.
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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/db
2
2
 
3
- * NodeJS 14
4
- * ES2019
3
+ * NodeJS 16
4
+ * ES2020
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,15 +9,16 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/index.d.ts
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.1/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DbDataSource } from "./squared";
16
16
 
17
17
  import type { IHost } from "./index";
18
18
  import type { ClientDbConstructor, IClientDb } from "./core";
19
- import type { DB_TYPE, SQL_COMMAND, BatchQueryResult, ExecuteBatchQueryOptions, ExecuteQueryOptions, HandleFailOptions, PoolConfig, ProcessRowsOptions, QueryResult } from "./db";
20
- import type { DbCoerceSettings, DbModule, DbSourceOptions } from "./settings";
19
+ import type { BatchQueryResult, DB_TYPE, ErrorQueryCallback, ExecuteBatchQueryOptions, ExecuteQueryOptions, HandleFailOptions, ProcessRowsOptions, QueryResult, SQL_COMMAND } from "./db";
20
+ import type { AuthValue } from "./http";
21
+ import type { DbCoerceSettings, DbModule, DbSourceOptions, PoolConfig } from "./settings";
21
22
 
22
23
  import type { SecureContextOptions } from "tls";
23
24
 
@@ -26,8 +27,10 @@ interface IDb extends IClientDb<IHost, DbModule, DbDataSource, DbSourceOptions,
26
27
  getCredential(item: DbDataSource): Record<string | number | symbol, unknown>;
27
28
  hasSource(source: string, ...type: number[]): boolean;
28
29
  applyCommand(...items: DbDataSource[]): void;
30
+ executeQuery(item: V, callback: ErrorQueryCallback): Promise<QueryResult>;
29
31
  executeQuery(item: DbDataSource, sessionKey: string): Promise<QueryResult>;
30
32
  executeQuery(item: DbDataSource, options?: ExecuteQueryOptions | string): Promise<QueryResult>;
33
+ executeBatchQuery(batch: DbDataSource[], callback: ErrorQueryCallback, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
31
34
  executeBatchQuery(batch: DbDataSource[], sessionKey: string, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
32
35
  executeBatchQuery(batch: DbDataSource[], options?: ExecuteBatchQueryOptions | string, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
33
36
  processRows(batch: DbDataSource[], tasks: Promise<QueryResult | null>[], parallel: boolean): Promise<BatchQueryResult>;
@@ -92,14 +95,119 @@ interface DbPoolConstructor {
92
95
  }
93
96
  ```
94
97
 
98
+ ## Settings
99
+
100
+ ```typescript
101
+ import type { DbSourceOptions, PurgeComponent } from "./settings";
102
+
103
+ interface DbModule {
104
+ // handler: "@e-mc/db";
105
+ mariadb?: DbStoredCredentials;
106
+ mongodb?: DbStoredCredentials;
107
+ mssql?: DbStoredCredentials;
108
+ mysql?: DbStoredCredentials;
109
+ oracle?: DbStoredCredentials;
110
+ postgres?: DbStoredCredentials;
111
+ redis?: DbStoredCredentials;
112
+ settings?: {
113
+ broadcast_id?: string | string[];
114
+ users?: Record<string, Record<string, unknown>>;
115
+ cache_dir?: string;
116
+ session_expires?: number;
117
+ user_key?: Record<string, DbSourceOptions>;
118
+ imports?: StringMap;
119
+ purge?: PurgeComponent;
120
+ mariadb?: DbSourceOptions;
121
+ mongodb?: DbSourceOptions;
122
+ mssql?: DbSourceOptions;
123
+ mysql?: DbSourceOptions;
124
+ oracle?: DbSourceOptions;
125
+ postgres?: DbSourceOptions;
126
+ redis?: DbSourceOptions;
127
+ };
128
+ }
129
+
130
+ type DbStoredCredentials = Record<string, Record<string, unknown>>;
131
+ ```
132
+
133
+ ### Example usage
134
+
135
+ ```javascript
136
+ const Db = require("@e-mc/db"); // Using @pi-r/mongodb
137
+
138
+ const instance = new Db({
139
+ mongodb: {
140
+ main: {
141
+ server: "localhost:27017",
142
+ auth: {
143
+ username: "**********",
144
+ password: "**********"
145
+ },
146
+ authMechanism: "SCRAM-SHA-1"
147
+ }
148
+ },
149
+ settings: {
150
+ mongodb: {
151
+ pool: {
152
+ max: 10,
153
+ idle: 60 * 1000,
154
+ queue_max: 4,
155
+ queue_idle: 30 * 1000,
156
+ timeout: 10 * 1000
157
+ },
158
+ cache: {
159
+ timeout: "1d",
160
+ when_empty: false
161
+ },
162
+ coerce: {
163
+ credential: false,
164
+ options: true
165
+ }
166
+ }
167
+ }
168
+ });
169
+ // instance.host = new Host();
170
+ instance.init();
171
+
172
+ const item = {
173
+ source: "mongodb",
174
+ credential: "main",
175
+ table: "demo",
176
+ name: "nodejs",
177
+ query: {
178
+ id: {
179
+ "$eq": "1"
180
+ }
181
+ },
182
+ willAbort: true
183
+ };
184
+ await instance.setCredential(item);
185
+
186
+ const rows = await instance.executeQuery(item, (err, item) => {
187
+ if (err.code === "E11000") {
188
+ return true; // throw err;
189
+ }
190
+ return false; // return [];
191
+ });
192
+
193
+ const [rows1, rows2] = await instance.executeBatchQuery([
194
+ { ...item, usePool: true },
195
+ { ...item, query: { id: { "$eq": "2" } } }
196
+ ],
197
+ { parallel: true, connectOnce: true }
198
+ );
199
+ ```
200
+
95
201
  ## References
96
202
 
97
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/squared.d.ts
98
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/core.d.ts
99
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/db.d.ts
100
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/object.d.ts
101
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/settings.d.ts
203
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/squared.d.ts
204
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/core.d.ts
205
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/db.d.ts
206
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/http.d.ts
207
+ - https://www.unpkg.com/@e-mc/types@0.9.1/lib/settings.d.ts
208
+
209
+ * https://www.npmjs.com/package/@types/node
102
210
 
103
211
  ## LICENSE
104
212
 
105
- MIT
213
+ BSD 3-Clause
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
4
3
  const types_1 = require("@e-mc/types");
5
4
  const core_1 = require("@e-mc/core");
@@ -8,15 +7,14 @@ const util_1 = require("@e-mc/db/util");
8
7
  const DB_CLIENT = new Map();
9
8
  const POOL_CONFIG = new Map();
10
9
  function sanitizePoolConfig(value) {
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);
10
+ value.min ?? (value.min = -1);
11
+ value.max ?? (value.max = -1);
12
+ value.idle ?? (value.idle = -1);
13
+ value.queue_max ?? (value.queue_max = -1);
14
+ value.queue_idle ?? (value.queue_idle = -1);
15
+ value.purge ?? (value.purge = 0);
16
+ value.timeout ?? (value.timeout = -1);
17
+ value.socket_timeout ?? (value.socket_timeout = -1);
20
18
  return value;
21
19
  }
22
20
  function setCert(items, cache) {
@@ -34,13 +32,12 @@ class Db extends core_1.ClientDb {
34
32
  this._threadable = true;
35
33
  }
36
34
  static async purgeMemory(percent = 1, limit = 0, parent) {
37
- var _a, _b;
38
35
  let result = 0;
39
36
  if (percent > 0 && percent <= 1) {
40
37
  for (const [name, client] of DB_CLIENT) {
41
- const purge = ((_a = POOL_CONFIG.get(name)) === null || _a === void 0 ? void 0 : _a.purge) || 0;
38
+ const purge = POOL_CONFIG.get(name)?.purge || 0;
42
39
  if (purge > 0) {
43
- const checkTimeout = (_b = client.checkTimeout) === null || _b === void 0 ? void 0 : _b.bind(client);
40
+ const checkTimeout = client.checkTimeout?.bind(client);
44
41
  if (checkTimeout) {
45
42
  try {
46
43
  result += await checkTimeout(purge, limit);
@@ -73,10 +70,9 @@ class Db extends core_1.ClientDb {
73
70
  }
74
71
  }
75
72
  getCredential(item) {
76
- var _a;
77
73
  let credential = item.credential, stored;
78
74
  if (typeof credential === 'string') {
79
- credential = (_a = this.module[item.source]) === null || _a === void 0 ? void 0 : _a[credential];
75
+ credential = this.module[item.source]?.[credential];
80
76
  stored = true;
81
77
  }
82
78
  if ((0, types_1.isPlainObject)(credential)) {
@@ -97,7 +93,6 @@ class Db extends core_1.ClientDb {
97
93
  }
98
94
  }
99
95
  applyCommand(...items) {
100
- var _a, _b, _c;
101
96
  let settings;
102
97
  for (let i = 0, length = items.length; i < length; ++i) {
103
98
  const item = items[i];
@@ -105,12 +100,12 @@ class Db extends core_1.ClientDb {
105
100
  if (!command) {
106
101
  continue;
107
102
  }
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)) {
103
+ if (!settings && !(0, types_1.isPlainObject)(settings = this.getUserSettings()?.[item.source]?.commands)) {
109
104
  return;
110
105
  }
111
106
  let name, table;
112
107
  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]);
113
- const data = (_c = settings[group]) === null || _c === void 0 ? void 0 : _c[procedure];
108
+ const data = settings[group]?.[procedure];
114
109
  if (!(0, types_1.isPlainObject)(data)) {
115
110
  continue;
116
111
  }
@@ -128,7 +123,10 @@ class Db extends core_1.ClientDb {
128
123
  }
129
124
  async executeQuery(item, options) {
130
125
  if (this.aborted) {
131
- return Promise.reject((0, types_1.createAbortError)());
126
+ return (0, types_1.createAbortError)(true);
127
+ }
128
+ if (typeof options === 'function') {
129
+ options = { errorQuery: options };
132
130
  }
133
131
  try {
134
132
  return this.getClient(item.source).executeQuery.call(this, item, options);
@@ -139,7 +137,10 @@ class Db extends core_1.ClientDb {
139
137
  }
140
138
  async executeBatchQuery(batch, options, outResult) {
141
139
  if (this.aborted) {
142
- return Promise.reject((0, types_1.createAbortError)());
140
+ return (0, types_1.createAbortError)(true);
141
+ }
142
+ if (typeof options === 'function') {
143
+ options = { errorQuery: options };
143
144
  }
144
145
  try {
145
146
  return this.getClient(batch[0].source).executeBatchQuery.call(this, batch, options, outResult);
@@ -215,11 +216,10 @@ class Db extends core_1.ClientDb {
215
216
  }
216
217
  async commit(items) {
217
218
  if (this.aborted) {
218
- return Promise.reject((0, types_1.createAbortError)());
219
+ return (0, types_1.createAbortError)(true);
219
220
  }
220
221
  const tasks = (items || this.pending).map(async (data) => {
221
- var _a;
222
- (_a = data.ignoreCache) !== null && _a !== void 0 ? _a : (data.ignoreCache = true);
222
+ data.ignoreCache ?? (data.ignoreCache = true);
223
223
  return this.executeQuery(data).catch(() => {
224
224
  this.applyState([data], 16);
225
225
  return [];
@@ -230,11 +230,11 @@ class Db extends core_1.ClientDb {
230
230
  readTLSCert(value, cache) {
231
231
  if ((0, types_1.isString)(value)) {
232
232
  let pathname = value.trim();
233
- if (request_1.default.isCert(pathname)) {
233
+ if (request_1.isCert(pathname)) {
234
234
  return pathname;
235
235
  }
236
236
  if (Db.isPath(pathname = path.resolve(pathname)) && this.canRead(pathname, { ownPermissionOnly: true })) {
237
- return request_1.default.readCACert(pathname, cache);
237
+ return request_1.readCACert(pathname, cache);
238
238
  }
239
239
  }
240
240
  return '';
@@ -259,10 +259,9 @@ class Db extends core_1.ClientDb {
259
259
  }
260
260
  }
261
261
  resolveSource(source, folder) {
262
- var _a;
263
262
  let result;
264
263
  if (!source.startsWith('@')) {
265
- result = ((_a = this.settings.imports) === null || _a === void 0 ? void 0 : _a[source]) || util_1.IMPORTS[source];
264
+ result = this.settings.imports?.[source] || util_1.IMPORTS[source];
266
265
  }
267
266
  else if (!folder && !source.includes('/')) {
268
267
  folder = 'client';
@@ -270,18 +269,17 @@ class Db extends core_1.ClientDb {
270
269
  return (result || source) + (folder ? '/' + folder : '');
271
270
  }
272
271
  getPoolConfig(source, uuidKey) {
273
- var _a, _b, _c, _d, _e, _f, _g;
274
272
  const config = Db.getPoolConfig(source);
275
273
  const result = uuidKey && this.settingsKey(uuidKey, 'pool');
276
274
  if (result) {
277
275
  if (config) {
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);
276
+ result.min ?? (result.min = config.min);
277
+ result.max ?? (result.max = config.max);
278
+ result.idle ?? (result.idle = config.idle);
279
+ result.queue_max ?? (result.queue_max = config.queue_max);
280
+ result.queue_idle ?? (result.queue_idle = config.queue_idle);
281
+ result.timeout ?? (result.timeout = config.timeout);
282
+ result.socket_timeout ?? (result.socket_timeout = config.socket_timeout);
285
283
  }
286
284
  else {
287
285
  sanitizePoolConfig(result);
@@ -303,7 +301,7 @@ class Db extends core_1.ClientDb {
303
301
  }
304
302
  try {
305
303
  client = require(this.resolveSource(source));
306
- if (client === null || client === void 0 ? void 0 : client.DB_SOURCE_CLIENT) {
304
+ if (client?.DB_SOURCE_CLIENT) {
307
305
  client.DB_SOURCE_NAME = source;
308
306
  DB_CLIENT.set(source, client);
309
307
  return client;
@@ -318,9 +316,5 @@ Db.STORE_RESULT_PARTITION_SIZE = 16;
318
316
  Db.STORE_RESULT_PARTITION_MULT = 2;
319
317
  Object.freeze(types_1.DB_TYPE);
320
318
  Object.freeze(util_1.SQL_COMMAND);
321
- exports.default = Db;
322
319
 
323
- if (exports.default) {
324
- module.exports = exports.default;
325
- module.exports.default = exports.default;
326
- }
320
+ module.exports = Db;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.8.10",
3
+ "version": "0.9.1",
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": "MIT",
20
+ "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.10",
24
- "@e-mc/request": "0.8.10",
25
- "@e-mc/types": "0.8.10"
23
+ "@e-mc/core": "0.9.1",
24
+ "@e-mc/request": "0.9.1",
25
+ "@e-mc/types": "0.9.1"
26
26
  }
27
27
  }
package/pool.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  var _a, _b, _c;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
3
  const types_1 = require("@e-mc/types");
5
4
  const util_1 = require("@e-mc/db/util");
6
5
  const kItems = Symbol('items');
@@ -30,17 +29,15 @@ class DbPool {
30
29
  }
31
30
  static validateKey(pools, username, uuidKey) {
32
31
  if ((0, types_1.validateUUID)(uuidKey)) {
33
- if ((0, types_1.isString)(username)) {
34
- for (const key in pools) {
35
- const pool = pools[key];
36
- const auth = pool.uuidKey;
37
- if ((auth === null || auth === void 0 ? void 0 : auth.username) === username && auth.password === uuidKey) {
38
- if (!pool.closed) {
39
- return [uuidKey, pool];
40
- }
41
- delete pools[key];
42
- break;
32
+ for (const key in pools) {
33
+ const pool = pools[key];
34
+ const auth = pool.uuidKey;
35
+ if (auth?.username === username && auth.password === uuidKey) {
36
+ if (!pool.closed) {
37
+ return [uuidKey, pool];
43
38
  }
39
+ delete pools[key];
40
+ break;
44
41
  }
45
42
  }
46
43
  return [uuidKey, null];
@@ -72,9 +69,8 @@ class DbPool {
72
69
  this[_c] = { success: -1, failed: -1, count: 0, error: 0 };
73
70
  }
74
71
  add(item, uuidKey) {
75
- var _d;
76
72
  this[kItems].add(item);
77
- if (uuidKey || (uuidKey = (_d = this.uuidKey) === null || _d === void 0 ? void 0 : _d.password)) {
73
+ if (uuidKey || (uuidKey = this.uuidKey?.password)) {
78
74
  (0, util_1.setUUIDKey)(item, uuidKey);
79
75
  }
80
76
  this.lastAccessed = Date.now();
@@ -140,9 +136,5 @@ class DbPool {
140
136
  }
141
137
  }
142
138
  _a = kItems, _b = kParent, _c = kIdlePrevious;
143
- exports.default = DbPool;
144
139
 
145
- if (exports.default) {
146
- module.exports = exports.default;
147
- module.exports.default = exports.default;
148
- }
140
+ module.exports = DbPool;
package/util.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { DbDataSource } from '../types/lib/squared';
2
2
 
3
3
  import type { DbConnection, SQL_COMMAND, ServerAuth } from '../types/lib/db';
4
+ import type { AuthValue } from '../types/lib/http';
4
5
 
5
6
  declare namespace util {
6
7
  const SQL_COMMAND: SQL_COMMAND;
package/util.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.hasBasicAuth = exports.getBasicAuth = exports.setUUIDKey = exports.checkEmpty = exports.parseConnectionString = exports.parseServerAuth = exports.IMPORTS = exports.SQL_COMMAND = void 0;
4
3
  const types_1 = require("@e-mc/types");
5
4
  const util_1 = require("@e-mc/request/util");
@@ -86,14 +85,13 @@ function parseServerAuth(credential, port, all) {
86
85
  }
87
86
  exports.parseServerAuth = parseServerAuth;
88
87
  function parseConnectionString(value, scheme = 'http') {
89
- var _a;
90
88
  if (!/^[^:]+:\/\//.test(value)) {
91
89
  value = scheme + '://' + value;
92
90
  }
93
91
  try {
94
92
  const { protocol, username, password, hostname, pathname, port, search } = new URL(value);
95
93
  const database = pathname.substring(1);
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 };
94
+ return { protocol, username: decodeURIComponent(username), password: decodeURIComponent(password), hostname, port, database: decodeURIComponent(/^([^?/#]+)/.exec(database)?.[1] || database), pathname, search };
97
95
  }
98
96
  catch {
99
97
  return null;