@e-mc/core 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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -8
  3. package/index.js +28 -28
  4. package/package.json +3 -3
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,7 +9,7 @@
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 { DataSource, LogStatus } from "./squared";
@@ -165,13 +165,13 @@ interface IPermission {
165
165
 
166
166
  ## References
167
167
 
168
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/squared.d.ts
169
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/core.d.ts
170
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/db.d.ts
171
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/dom.d.ts
172
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/logger.d.ts
173
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/node.d.ts
174
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/settings.d.ts
168
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/squared.d.ts
169
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/core.d.ts
170
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/db.d.ts
171
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/dom.d.ts
172
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/logger.d.ts
173
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/node.d.ts
174
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
175
175
 
176
176
  ## LICENSE
177
177
 
package/index.js CHANGED
@@ -5,8 +5,8 @@ exports.Module = exports.Permission = exports.AbortComponent = exports.ClientDb
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');
@@ -26,7 +26,7 @@ const HOST = {
26
26
  DONE: new Map(),
27
27
  QUEUE: [],
28
28
  QUEUE_LIMIT: Infinity,
29
- QUEUE_EXPIRES: 86400000 /* VALUES.HOST_EXPIRES */,
29
+ QUEUE_EXPIRES: 86400000,
30
30
  PID: 1,
31
31
  CLOSED: 0,
32
32
  QUEUED: 0,
@@ -38,7 +38,7 @@ const HOST = {
38
38
  ADMIN_USERS: [],
39
39
  ADMIN_PRIVATE: false,
40
40
  THREAD_LIMIT: Infinity,
41
- THREAD_EXPIRES: 86400000 /* VALUES.HOST_EXPIRES */,
41
+ THREAD_EXPIRES: 86400000,
42
42
  PRIORITY_MIN: 0,
43
43
  PRIORITY_MAX: 100,
44
44
  PRIORITY_BYPASS: undefined
@@ -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 isInvalidRange(result, range) {
@@ -225,8 +225,8 @@ function asPosix(value) {
225
225
  return PLATFORM_WIN32 ? value.replace(/(?:^\\|\\+)/g, '/') : value;
226
226
  }
227
227
  const readable = (value) => (0, types_1.isString)(value) || (0, types_1.isArray)(value);
228
- const expireTime = (value) => Date.now() + value * 1000 /* TIME.S */;
229
- const convertSeconds = (value) => typeof value === 'string' && Math.ceil((0, types_1.parseTime)(value) / 1000 /* TIME.S */) || 0;
228
+ const expireTime = (value) => Date.now() + value * 1000;
229
+ const convertSeconds = (value) => typeof value === 'string' && Math.ceil((0, types_1.parseTime)(value) / 1000) || 0;
230
230
  class Host extends module_1.default {
231
231
  static async purgeMemory(percent = 1, limit = 0, parent) {
232
232
  return parent ? super.purgeMemory(percent, limit) : 0;
@@ -386,7 +386,7 @@ class Host extends module_1.default {
386
386
  closeThread(host);
387
387
  }
388
388
  else if (host.startTime + HOST.THREAD_EXPIRES >= current) {
389
- 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 });
389
+ host.writeFail(["Transaction was cancelled", host.username], (0, types_1.errorValue)("Timeout was exceeded", (0, types_1.formatTime)(HOST.THREAD_EXPIRES)), { fatal: true });
390
390
  host.abort();
391
391
  closeThread(host);
392
392
  }
@@ -712,12 +712,12 @@ class Client extends module_1.default {
712
712
  exports.Client = Client;
713
713
  _c = kCacheDir;
714
714
  class ClientDb extends Client {
715
- static get TRANSACTION_ACTIVE() { return 1 /* DB_TRANSACTION.ACTIVE */; }
716
- static get TRANSACTION_PARTIAL() { return 2 /* DB_TRANSACTION.PARTIAL */; }
717
- static get TRANSACTION_COMMIT() { return 4 /* DB_TRANSACTION.COMMIT */; }
718
- static get TRANSACTION_TERMINATE() { return 8 /* DB_TRANSACTION.TERMINATE */; }
719
- static get TRANSACTION_ABORT() { return 16 /* DB_TRANSACTION.ABORT */; }
720
- static get TRANSACTION_FAIL() { return 32 /* DB_TRANSACTION.FAIL */; }
715
+ static get TRANSACTION_ACTIVE() { return 1; }
716
+ static get TRANSACTION_PARTIAL() { return 2; }
717
+ static get TRANSACTION_COMMIT() { return 4; }
718
+ static get TRANSACTION_TERMINATE() { return 8; }
719
+ static get TRANSACTION_ABORT() { return 16; }
720
+ static get TRANSACTION_FAIL() { return 32; }
721
721
  static loadSettings(settings, password) {
722
722
  if (!super.loadSettings({ process: settings.process }, password)) {
723
723
  return false;
@@ -782,7 +782,7 @@ class ClientDb extends Client {
782
782
  let result = 0;
783
783
  switch (typeof value) {
784
784
  case 'number':
785
- result = value * 1000 /* TIME.S */;
785
+ result = value * 1000;
786
786
  break;
787
787
  case 'string':
788
788
  result = (0, types_1.parseTime)(value);
@@ -901,7 +901,7 @@ class ClientDb extends Client {
901
901
  else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
902
902
  const dbKey = userKey + sessionKey;
903
903
  ((_k = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_k[dbKey] = {}))[queryString] = result;
904
- setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000 /* TIME.S */);
904
+ setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
905
905
  }
906
906
  }
907
907
  return result;
@@ -971,7 +971,7 @@ class ClientDb extends Client {
971
971
  constructor(data, database = []) {
972
972
  super(data);
973
973
  this.database = database;
974
- this.cacheExpires = 600000 /* VALUES.DB_EXPIRES */;
974
+ this.cacheExpires = 600000;
975
975
  }
976
976
  init(config) {
977
977
  let { cache_dir, session_expires: expires } = this.settings;
@@ -1076,7 +1076,7 @@ class ClientDb extends Client {
1076
1076
  }
1077
1077
  const uuidKey = ClientDb.extractUUID(credential);
1078
1078
  let options;
1079
- if (ClientDb.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, this.host?.username)) {
1079
+ if (ClientDb.enabled("memory.settings.users", this.host?.username)) {
1080
1080
  let value, exclusiveOf;
1081
1081
  if ((0, types_1.isObject)(sessionKey)) {
1082
1082
  ({ value, sessionKey, exclusiveOf } = sessionKey);
@@ -1102,13 +1102,13 @@ class ClientDb extends Client {
1102
1102
  }
1103
1103
  applyState(items, value, as) {
1104
1104
  for (const item of Array.isArray(items) ? items : [items]) {
1105
- if ((0, types_1.hasBit)(value, 8 /* DB_TRANSACTION.TERMINATE */)) {
1105
+ if ((0, types_1.hasBit)(value, 8)) {
1106
1106
  const state = item.transactionState || (item.transactionState = 0);
1107
- if ((0, types_1.hasBit)(state, 4 /* DB_TRANSACTION.COMMIT */) || (0, types_1.hasBit)(state, 32 /* DB_TRANSACTION.FAIL */)) {
1107
+ if ((0, types_1.hasBit)(state, 4) || (0, types_1.hasBit)(state, 32)) {
1108
1108
  item.transactionState |= value;
1109
1109
  }
1110
1110
  }
1111
- else if ((0, types_1.hasBit)(value, 16 /* DB_TRANSACTION.ABORT */)) {
1111
+ else if ((0, types_1.hasBit)(value, 16)) {
1112
1112
  item.transactionState || (item.transactionState = value);
1113
1113
  }
1114
1114
  else if (as) {
@@ -1141,19 +1141,19 @@ class ClientDb extends Client {
1141
1141
  get pending() {
1142
1142
  return this.database.filter(item => {
1143
1143
  const state = item.transactionState || 0;
1144
- return state === 0 || state === 16 /* DB_TRANSACTION.ABORT */;
1144
+ return state === 0 || state === 16;
1145
1145
  });
1146
1146
  }
1147
1147
  get committed() {
1148
- return this.database.filter(item => (item.transactionState & 4 /* DB_TRANSACTION.COMMIT */) === 4 /* DB_TRANSACTION.COMMIT */);
1148
+ return this.database.filter(item => (item.transactionState & 4) === 4);
1149
1149
  }
1150
1150
  get failed() {
1151
- return this.database.filter(item => (item.transactionState & 32 /* DB_TRANSACTION.FAIL */) === 32 /* DB_TRANSACTION.FAIL */);
1151
+ return this.database.filter(item => (item.transactionState & 32) === 32);
1152
1152
  }
1153
1153
  }
1154
1154
  exports.ClientDb = ClientDb;
1155
- ClientDb.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_SIZE */;
1156
- ClientDb.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_MULT */;
1155
+ ClientDb.STORE_RESULT_PARTITION_SIZE = 16;
1156
+ ClientDb.STORE_RESULT_PARTITION_MULT = 2;
1157
1157
  class AbortComponent {
1158
1158
  constructor() {
1159
1159
  this[_d] = new AbortController();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/core",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Core 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/module": "0.8.4",
24
- "@e-mc/types": "0.8.4",
23
+ "@e-mc/module": "0.8.6",
24
+ "@e-mc/types": "0.8.6",
25
25
  "picomatch": "^3.0.1"
26
26
  }
27
27
  }