@e-mc/db 0.8.4 → 0.8.6

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,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
package/README.md CHANGED
@@ -9,14 +9,14 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.6/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 { BatchQueryResult, DB_TYPE, ExecuteBatchQueryOptions, ExecuteQueryOptions, HandleFailOptions, PoolConfig, ProcessRowsOptions, QueryResult, SQL_COMMAND } from "./db";
19
+ import type { DB_TYPE, SQL_COMMAND, BatchQueryResult, ExecuteBatchQueryOptions, ExecuteQueryOptions, HandleFailOptions, PoolConfig, ProcessRowsOptions, QueryResult } from "./db";
20
20
  import type { DbCoerceSettings, DbModule, DbSourceOptions } from "./settings";
21
21
 
22
22
  import type { SecureContextOptions } from "tls";
@@ -94,11 +94,11 @@ interface DbPoolConstructor {
94
94
 
95
95
  ## References
96
96
 
97
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/squared.d.ts
98
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/core.d.ts
99
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/db.d.ts
100
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/object.d.ts
101
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/settings.d.ts
97
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/squared.d.ts
98
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/core.d.ts
99
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/db.d.ts
100
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/object.d.ts
101
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
102
102
 
103
103
  ## LICENSE
104
104
 
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) {
@@ -67,7 +67,7 @@ class Db extends core_1.ClientDb {
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) {
@@ -150,7 +150,7 @@ class Db extends core_1.ClientDb {
150
150
  ({ disconnect, parallel } = parallel);
151
151
  }
152
152
  const terminate = () => {
153
- this.applyState(batch, 8 /* DB_TRANSACTION.TERMINATE */);
153
+ this.applyState(batch, 8);
154
154
  if (typeof disconnect === 'function') {
155
155
  try {
156
156
  disconnect();
@@ -160,7 +160,7 @@ class Db extends core_1.ClientDb {
160
160
  }
161
161
  };
162
162
  const cleanup = () => {
163
- this.applyState(batch, 16 /* DB_TRANSACTION.ABORT */);
163
+ this.applyState(batch, 16);
164
164
  terminate();
165
165
  if (outResult) {
166
166
  for (let i = 0, length = outResult.length; i < length; ++i) {
@@ -191,7 +191,7 @@ class Db extends core_1.ClientDb {
191
191
  .catch(() => cleanup());
192
192
  }
193
193
  handleFail(err, item, options) {
194
- this.add(item, 32 /* DB_TRANSACTION.FAIL */);
194
+ this.add(item, 32);
195
195
  item.transactionFail = true;
196
196
  if (options && typeof options.errorQuery === 'function') {
197
197
  if (options.errorQuery(err, item, options.commandType)) {
@@ -205,7 +205,7 @@ class Db extends core_1.ClientDb {
205
205
  if (item.willAbort) {
206
206
  this.abort(err);
207
207
  }
208
- this.writeFail(["Unable to execute query" /* ERR_DB.EXEC_QUERY */, item.source], err, 65536 /* LOG_TYPE.DB */);
208
+ this.writeFail(["Unable to execute query", item.source], err, 65536);
209
209
  }
210
210
  return false;
211
211
  }
@@ -216,11 +216,11 @@ class Db extends core_1.ClientDb {
216
216
  const tasks = (items || this.pending).map(async (data) => {
217
217
  data.ignoreCache ?? (data.ignoreCache = true);
218
218
  return this.executeQuery(data).catch(() => {
219
- this.applyState([data], 16 /* DB_TRANSACTION.ABORT */);
219
+ this.applyState([data], 16);
220
220
  return [];
221
221
  });
222
222
  });
223
- return tasks.length === 0 ? false : this.allSettled(tasks, ["Execute unassigned queries" /* VAL_DB.EXEC_QUERYUNASSIGNED */, this.moduleName]).then(result => result.length > 0).catch(() => false);
223
+ return tasks.length === 0 ? false : this.allSettled(tasks, ["Execute unassigned queries", this.moduleName]).then(result => result.length > 0).catch(() => false);
224
224
  }
225
225
  readTLSCert(value, cache) {
226
226
  if ((0, types_1.isString)(value)) {
@@ -304,11 +304,11 @@ class Db extends core_1.ClientDb {
304
304
  }
305
305
  catch {
306
306
  }
307
- throw (0, types_1.errorMessage)(source, "Database provider not found" /* ERR_DB.PROVIDER_NOTFOUND */);
307
+ throw (0, types_1.errorMessage)(source, "Database provider not found");
308
308
  }
309
309
  }
310
- Db.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.DB_PARTITION_SIZE */;
311
- Db.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.DB_PARTITION_MULT */;
310
+ Db.STORE_RESULT_PARTITION_SIZE = 16;
311
+ Db.STORE_RESULT_PARTITION_MULT = 2;
312
312
  Object.freeze(types_1.DB_TYPE);
313
313
  Object.freeze(util_1.SQL_COMMAND);
314
314
  exports.default = Db;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.4",
24
- "@e-mc/request": "0.8.4",
25
- "@e-mc/types": "0.8.4"
23
+ "@e-mc/core": "0.8.6",
24
+ "@e-mc/request": "0.8.6",
25
+ "@e-mc/types": "0.8.6"
26
26
  }
27
27
  }
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');
@@ -116,7 +116,7 @@ class DbPool {
116
116
  }
117
117
  previous.success = success;
118
118
  previous.failed = failed;
119
- 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 */);
119
+ return Date.now() - timeout >= this.lastAccessed && (this.closeable || count >= (this.uuidKey ? 10 : 5)) || error >= (this.uuidKey ? 3 : 2);
120
120
  }
121
121
  get persist() {
122
122
  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;