@e-mc/core 0.7.1 → 0.7.3

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.
Files changed (4) hide show
  1. package/LICENSE +4 -8
  2. package/README.md +5 -3
  3. package/index.js +48 -49
  4. package/package.json +5 -5
package/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2023 Sukina
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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
4
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
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.
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/core
1
+ # @e-mc/core
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever 2056
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
package/index.js CHANGED
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Module = exports.Permission = exports.AbortComponent = exports.ClientDb = exports.Client = exports.Host = void 0;
5
5
  const path = require("path");
6
6
  const fs = require("fs");
7
7
  const pm = require("picomatch");
8
- const types_1 = require("../types");
9
- const module_1 = require("../module");
8
+ const types_1 = require("@e-mc/types");
9
+ const module_1 = require("@e-mc/module");
10
10
  exports.Module = module_1.default;
11
11
  const kConfig = Symbol('config');
12
12
  const kQueued = Symbol('queued');
13
- const kUsername = Symbol('username');
14
13
  const kAbortHandler = Symbol('abortHandler');
15
14
  const kFreeze = Symbol('freeze');
16
15
  const kDone = Symbol('done');
@@ -27,7 +26,7 @@ const HOST = {
27
26
  DONE: new Map(),
28
27
  QUEUE: [],
29
28
  QUEUE_LIMIT: Infinity,
30
- QUEUE_EXPIRES: 86400000 /* VALUES.HOST_EXPIRES */,
29
+ QUEUE_EXPIRES: 86400000,
31
30
  PID: 1,
32
31
  CLOSED: 0,
33
32
  QUEUED: 0,
@@ -39,12 +38,13 @@ const HOST = {
39
38
  ADMIN_USERS: [],
40
39
  ADMIN_PRIVATE: false,
41
40
  THREAD_LIMIT: Infinity,
42
- THREAD_EXPIRES: 86400000 /* VALUES.HOST_EXPIRES */,
41
+ THREAD_EXPIRES: 86400000,
43
42
  PRIORITY_MIN: 0,
44
43
  PRIORITY_MAX: 100,
45
44
  PRIORITY_BYPASS: undefined
46
45
  };
47
46
  const PLATFORM_WIN32 = process.platform === 'win32';
47
+ const HOST_USERNAME = new WeakMap();
48
48
  let STORE_RESULT_COUNT = 0;
49
49
  let PICOMATCH_OPTIONS = { nocase: PLATFORM_WIN32 };
50
50
  let MINIMATCH_OPTIONS = { matchBase: true, nocase: PLATFORM_WIN32 };
@@ -78,7 +78,7 @@ function callResumeThread(item, aborted) {
78
78
  if (item.joined) {
79
79
  const { instance, args = [], startTime } = item;
80
80
  if (!aborted) {
81
- instance.writeTimeElapsed('JOIN', ['Thread restarting...', HOST.THREAD_LIMIT > 1 ? 'Availability: ' + HOST.DONE.size + ' / ' + HOST.THREAD_LIMIT : ''], startTime, { type: 2 /* LOG_TYPE.NODE */, ...module_1.default.LOG_STYLE_WARN });
81
+ instance.writeTimeElapsed('JOIN', ['Thread restarting...', HOST.THREAD_LIMIT > 1 ? 'Availability: ' + HOST.DONE.size + ' / ' + HOST.THREAD_LIMIT : ''], startTime, { type: 2, ...module_1.default.LOG_STYLE_WARN });
82
82
  }
83
83
  queueMicrotask(() => {
84
84
  try {
@@ -90,7 +90,7 @@ function callResumeThread(item, aborted) {
90
90
  }
91
91
  }
92
92
  function cancelThread(host, hint, rejected) {
93
- host.writeFail(["Transaction was cancelled" /* ERR_MESSAGE.CANCELLED */, host.username], (0, types_1.errorValue)("Thread was killed" /* ERR_MESSAGE.THREAD_KILLED */, hint), { type: 2 /* LOG_TYPE.NODE */, fatal: true });
93
+ host.writeFail(["Transaction was cancelled", host.username], (0, types_1.errorValue)("Thread was killed", hint), { type: 2, fatal: true });
94
94
  host.abort();
95
95
  if (rejected) {
96
96
  ++HOST.REJECTED;
@@ -213,7 +213,7 @@ function resumeHostQueue(host) {
213
213
  }
214
214
  function updateHostQueue(host, position, priority, broadcast) {
215
215
  if (!broadcast || host.broadcastId) {
216
- host.formatMessage(2 /* LOG_TYPE.NODE */, 'QUEUE', ["Thread limit exceeded" /* ERR_MESSAGE.THREAD */ + ` (position #${position + 1})`, host.username], 'Priority: ' + priority, { type: 2 /* LOG_TYPE.NODE */, ...module_1.default.LOG_STYLE_WARN });
216
+ host.formatMessage(2, 'QUEUE', ["Thread limit exceeded" + ` (position #${position + 1})`, host.username], 'Priority: ' + priority, { type: 2, ...module_1.default.LOG_STYLE_WARN });
217
217
  }
218
218
  }
219
219
  function asPosix(value) {
@@ -221,8 +221,8 @@ function asPosix(value) {
221
221
  return PLATFORM_WIN32 ? value.replace(/\\/g, '/') : value;
222
222
  }
223
223
  const readable = (value) => (0, types_1.isString)(value) || (0, types_1.isArray)(value);
224
- const expireTime = (value) => Date.now() + value * 1000 /* TIME.S */;
225
- const convertSeconds = (value) => typeof value === 'string' && Math.ceil((0, types_1.parseTime)(value) / 1000 /* TIME.S */) || 0;
224
+ const expireTime = (value) => Date.now() + value * 1000;
225
+ const convertSeconds = (value) => typeof value === 'string' && Math.ceil((0, types_1.parseTime)(value) / 1000) || 0;
226
226
  class Host extends module_1.default {
227
227
  static purgeMemory(percent = 1, limit = 0, parent) {
228
228
  return parent ? super.purgeMemory(percent, limit) : Promise.resolve(0);
@@ -382,7 +382,7 @@ class Host extends module_1.default {
382
382
  closeThread(host);
383
383
  }
384
384
  else if (host.startTime + HOST.THREAD_EXPIRES >= current) {
385
- host.writeFail(["Transaction was cancelled" /* ERR_MESSAGE.CANCELLED */, host.username], (0, types_1.errorValue)("Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */, (0, types_1.formatTime)(HOST.THREAD_EXPIRES)), { fatal: true });
385
+ host.writeFail(["Transaction was cancelled", host.username], (0, types_1.errorValue)("Timeout was exceeded", (0, types_1.formatTime)(HOST.THREAD_EXPIRES)), { fatal: true });
386
386
  host.abort();
387
387
  closeThread(host);
388
388
  }
@@ -438,10 +438,9 @@ class Host extends module_1.default {
438
438
  this._usingObjects = new Set();
439
439
  this[_a] = false;
440
440
  this[_b] = false;
441
- this[_c] = '';
442
441
  const { broadcastId, log, username, priority } = config;
443
442
  if ((0, types_1.isString)(username)) {
444
- this[kUsername] = username;
443
+ HOST_USERNAME.set(this, username);
445
444
  }
446
445
  if (broadcastId) {
447
446
  this.broadcastId = broadcastId;
@@ -632,7 +631,7 @@ class Host extends module_1.default {
632
631
  return this[kConfig];
633
632
  }
634
633
  get username() {
635
- return this[kUsername];
634
+ return HOST_USERNAME.get(this) || '';
636
635
  }
637
636
  set done(value) {
638
637
  if (value) {
@@ -651,7 +650,7 @@ class Host extends module_1.default {
651
650
  }
652
651
  }
653
652
  exports.Host = Host;
654
- _a = kDone, _b = kQueued, _c = kUsername;
653
+ _a = kDone, _b = kQueued;
655
654
  class Client extends module_1.default {
656
655
  static purgeMemory(percent = 1, limit = 0, parent) {
657
656
  return parent ? super.purgeMemory(percent, limit) : Promise.resolve(0);
@@ -659,7 +658,7 @@ class Client extends module_1.default {
659
658
  constructor(data) {
660
659
  super();
661
660
  this._extensions = null;
662
- this[_d] = '';
661
+ this[_c] = '';
663
662
  this.module = (0, types_1.isPlainObject)(data) ? data : {};
664
663
  }
665
664
  init(...args) {
@@ -688,8 +687,8 @@ class Client extends module_1.default {
688
687
  return this[kCacheDir];
689
688
  }
690
689
  get settings() {
691
- var _k;
692
- return ((_k = this.module).settings || (_k.settings = {}));
690
+ var _j;
691
+ return ((_j = this.module).settings || (_j.settings = {}));
693
692
  }
694
693
  set extensions(values) {
695
694
  if (Array.isArray(values)) {
@@ -702,14 +701,14 @@ class Client extends module_1.default {
702
701
  }
703
702
  }
704
703
  exports.Client = Client;
705
- _d = kCacheDir;
704
+ _c = kCacheDir;
706
705
  class ClientDb extends Client {
707
- static get TRANSACTION_ACTIVE() { return 1 /* DB_TRANSACTION.ACTIVE */; }
708
- static get TRANSACTION_PARTIAL() { return 2 /* DB_TRANSACTION.PARTIAL */; }
709
- static get TRANSACTION_COMMIT() { return 4 /* DB_TRANSACTION.COMMIT */; }
710
- static get TRANSACTION_TERMINATE() { return 8 /* DB_TRANSACTION.TERMINATE */; }
711
- static get TRANSACTION_ABORT() { return 16 /* DB_TRANSACTION.ABORT */; }
712
- static get TRANSACTION_FAIL() { return 32 /* DB_TRANSACTION.FAIL */; }
706
+ static get TRANSACTION_ACTIVE() { return 1; }
707
+ static get TRANSACTION_PARTIAL() { return 2; }
708
+ static get TRANSACTION_COMMIT() { return 4; }
709
+ static get TRANSACTION_TERMINATE() { return 8; }
710
+ static get TRANSACTION_ABORT() { return 16; }
711
+ static get TRANSACTION_FAIL() { return 32; }
713
712
  static loadSettings(settings, password) {
714
713
  if (super.loadSettings({ process: settings.process }, password)) {
715
714
  const memory = settings.memory;
@@ -774,7 +773,7 @@ class ClientDb extends Client {
774
773
  let result = 0;
775
774
  switch (typeof value) {
776
775
  case 'number':
777
- result = value * 1000 /* TIME.S */;
776
+ result = value * 1000;
778
777
  break;
779
778
  case 'string':
780
779
  result = (0, types_1.parseTime)(value);
@@ -827,7 +826,7 @@ class ClientDb extends Client {
827
826
  }
828
827
  }
829
828
  static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
830
- var _k, _l;
829
+ var _j, _k;
831
830
  let cache, cacheDir;
832
831
  if ((0, types_1.isObject)(sessionKey)) {
833
832
  ({ cacheDir, sessionKey, sessionExpires } = sessionKey);
@@ -870,7 +869,7 @@ class ClientDb extends Client {
870
869
  queryString = this.asHash(queryString);
871
870
  if (timeout > 0) {
872
871
  const item = [expireTime(timeout), result, Date.now(), 0];
873
- ((_k = (CACHE_USER[source] || (CACHE_USER[source] = {})))[userKey] || (_k[userKey] = {}))[queryString] = item;
872
+ ((_j = (CACHE_USER[source] || (CACHE_USER[source] = {})))[userKey] || (_j[userKey] = {}))[queryString] = item;
874
873
  addSourceResult(source, item);
875
874
  if (cacheDir) {
876
875
  if (partition) {
@@ -892,17 +891,17 @@ class ClientDb extends Client {
892
891
  }
893
892
  else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
894
893
  const dbKey = userKey + sessionKey;
895
- ((_l = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_l[dbKey] = {}))[queryString] = result;
896
- setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000 /* TIME.S */);
894
+ ((_k = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_k[dbKey] = {}))[queryString] = result;
895
+ setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
897
896
  }
898
897
  }
899
898
  return result;
900
899
  }
901
- static purgeResult(prefix) {
900
+ static async purgeResult(prefix) {
902
901
  const current = Date.now();
903
902
  const providers = new Map();
904
903
  if (prefix) {
905
- if (prefix.indexOf('_') === -1) {
904
+ if (!prefix.includes('_')) {
906
905
  prefix += '_';
907
906
  for (const key in CACHE_USER) {
908
907
  if (key.startsWith(prefix)) {
@@ -963,7 +962,7 @@ class ClientDb extends Client {
963
962
  constructor(data, database = []) {
964
963
  super(data);
965
964
  this.database = database;
966
- this.cacheExpires = 600000 /* VALUES.DB_EXPIRES */;
965
+ this.cacheExpires = 600000;
967
966
  }
968
967
  init(config) {
969
968
  let { cache_dir, session_expires: expires } = this.settings;
@@ -1057,7 +1056,7 @@ class ClientDb extends Client {
1057
1056
  }
1058
1057
  const uuidKey = ClientDb.extractUUID(credential);
1059
1058
  let options;
1060
- if (ClientDb.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, this.host?.username)) {
1059
+ if (ClientDb.enabled("memory.settings.users", this.host?.username)) {
1061
1060
  let value;
1062
1061
  if ((0, types_1.isObject)(sessionKey)) {
1063
1062
  ({ value, sessionKey } = sessionKey);
@@ -1077,13 +1076,13 @@ class ClientDb extends Client {
1077
1076
  }
1078
1077
  applyState(items, value, as) {
1079
1078
  for (const item of Array.isArray(items) ? items : [items]) {
1080
- if ((0, types_1.hasBit)(value, 8 /* DB_TRANSACTION.TERMINATE */)) {
1079
+ if ((0, types_1.hasBit)(value, 8)) {
1081
1080
  const state = item.transactionState || (item.transactionState = 0);
1082
- if ((0, types_1.hasBit)(state, 4 /* DB_TRANSACTION.COMMIT */) || (0, types_1.hasBit)(state, 32 /* DB_TRANSACTION.FAIL */)) {
1081
+ if ((0, types_1.hasBit)(state, 4) || (0, types_1.hasBit)(state, 32)) {
1083
1082
  item.transactionState |= value;
1084
1083
  }
1085
1084
  }
1086
- else if ((0, types_1.hasBit)(value, 16 /* DB_TRANSACTION.ABORT */)) {
1085
+ else if ((0, types_1.hasBit)(value, 16)) {
1087
1086
  item.transactionState || (item.transactionState = value);
1088
1087
  }
1089
1088
  else if (as) {
@@ -1107,8 +1106,8 @@ class ClientDb extends Client {
1107
1106
  }
1108
1107
  }
1109
1108
  settingsKey(uuidKey, name, component) {
1110
- var _k;
1111
- const data = ((_k = this.settings).user_key || (_k.user_key = {}))[uuidKey];
1109
+ var _j;
1110
+ const data = ((_j = this.settings).user_key || (_j.user_key = {}))[uuidKey];
1112
1111
  if ((0, types_1.isObject)(data)) {
1113
1112
  return getSettingsValue(data, name, component);
1114
1113
  }
@@ -1116,22 +1115,22 @@ class ClientDb extends Client {
1116
1115
  get pending() {
1117
1116
  return this.database.filter(item => {
1118
1117
  const state = item.transactionState || 0;
1119
- return state === 0 || state === 16 /* DB_TRANSACTION.ABORT */;
1118
+ return state === 0 || state === 16;
1120
1119
  });
1121
1120
  }
1122
1121
  get committed() {
1123
- return this.database.filter(item => (item.transactionState & 4 /* DB_TRANSACTION.COMMIT */) === 4 /* DB_TRANSACTION.COMMIT */);
1122
+ return this.database.filter(item => (item.transactionState & 4) === 4);
1124
1123
  }
1125
1124
  get failed() {
1126
- return this.database.filter(item => (item.transactionState & 32 /* DB_TRANSACTION.FAIL */) === 32 /* DB_TRANSACTION.FAIL */);
1125
+ return this.database.filter(item => (item.transactionState & 32) === 32);
1127
1126
  }
1128
1127
  }
1129
1128
  exports.ClientDb = ClientDb;
1130
- ClientDb.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_SIZE */;
1131
- ClientDb.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_MULT */;
1129
+ ClientDb.STORE_RESULT_PARTITION_SIZE = 16;
1130
+ ClientDb.STORE_RESULT_PARTITION_MULT = 2;
1132
1131
  class AbortComponent {
1133
1132
  constructor() {
1134
- this[_e] = new AbortController();
1133
+ this[_d] = new AbortController();
1135
1134
  }
1136
1135
  static attach(instance, signal, options) {
1137
1136
  let map = ABORT_LISTENER.get(instance);
@@ -1171,7 +1170,7 @@ class AbortComponent {
1171
1170
  }
1172
1171
  }
1173
1172
  exports.AbortComponent = AbortComponent;
1174
- _e = kAbortHandler;
1173
+ _d = kAbortHandler;
1175
1174
  class Permission {
1176
1175
  static create(settings, parent, freeze) {
1177
1176
  if (this.validate(settings)) {
@@ -1260,10 +1259,10 @@ class Permission {
1260
1259
  return '';
1261
1260
  }
1262
1261
  constructor(freeze = false) {
1262
+ this[_e] = { enabled: null, value: '' };
1263
1263
  this[_f] = { enabled: null, value: '' };
1264
1264
  this[_g] = { enabled: null, value: '' };
1265
1265
  this[_h] = { enabled: null, value: '' };
1266
- this[_j] = { enabled: null, value: '' };
1267
1266
  this[kFreeze] = freeze;
1268
1267
  }
1269
1268
  setDiskRead(pathname = '', enabled = true) {
@@ -1316,5 +1315,5 @@ class Permission {
1316
1315
  }
1317
1316
  }
1318
1317
  exports.Permission = Permission;
1319
- _f = kDiskRead, _g = kDiskWrite, _h = kUncRead, _j = kUncWrite;
1318
+ _e = kDiskRead, _f = kDiskWrite, _g = kUncRead, _h = kUncWrite;
1320
1319
  PERMISSION = Host.createPermission(true, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/core",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Core 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/core"
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/module": "0.7.1",
24
- "@e-mc/types": "0.7.1",
23
+ "@e-mc/module": "0.7.3",
24
+ "@e-mc/types": "0.7.3",
25
25
  "picomatch": "^3.0.1"
26
26
  }
27
27
  }