@e-mc/core 0.12.12 → 0.12.14

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 (3) hide show
  1. package/README.md +9 -9
  2. package/index.js +20 -11
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.12/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.14/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, LogStatus, WorkerAction } from "./squared";
@@ -74,7 +74,7 @@ interface HostConstructor extends ModuleConstructor {
74
74
  getThreadCount(full: true): ThreadCountStat;
75
75
  getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
76
76
  getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
77
- getPermissionFromSettings(): IPermission;
77
+ getPermissionFromSettings(freeze?: boolean): IPermission;
78
78
  readonly prototype: IHost;
79
79
  new(config?: HostInitConfig): IHost;
80
80
  }
@@ -319,13 +319,13 @@ NOTE: **@e-mc/core** is mostly a collection of abstract base classes which canno
319
319
 
320
320
  ## References
321
321
 
322
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/squared.d.ts
323
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/core.d.ts
324
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/db.d.ts
325
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/dom.d.ts
326
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/logger.d.ts
327
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/node.d.ts
328
- - https://www.unpkg.com/@e-mc/types@0.12.12/lib/settings.d.ts
322
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/squared.d.ts
323
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/core.d.ts
324
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/db.d.ts
325
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/dom.d.ts
326
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/logger.d.ts
327
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/node.d.ts
328
+ - https://www.unpkg.com/@e-mc/types@0.12.14/lib/settings.d.ts
329
329
 
330
330
  * https://www.npmjs.com/package/@types/node
331
331
 
package/index.js CHANGED
@@ -217,7 +217,7 @@ function getSettingsValue(options, name, component) {
217
217
  }
218
218
  function isInvalidRange(result, range) {
219
219
  const [lower, upper = 0] = range;
220
- return result.length <= lower || upper > 0 && result.length > upper;
220
+ return Array.isArray(result) && (result.length <= lower || upper > 0 && result.length > upper);
221
221
  }
222
222
  function asPosix(value) {
223
223
  if (module_1.PLATFORM_WIN32) {
@@ -281,6 +281,7 @@ class Host extends module_1 {
281
281
  if (permission.unc_write) {
282
282
  PERMISSION.setUNCWrite(unc_write);
283
283
  }
284
+ Object.freeze(PERMISSION);
284
285
  }
285
286
  if (perm.settings) {
286
287
  const { picomatch: pico, minimatch: mini } = perm.settings;
@@ -486,8 +487,8 @@ class Host extends module_1 {
486
487
  static getLogDelayed() {
487
488
  return HOST.LOG_DELAYED;
488
489
  }
489
- static getPermissionFromSettings() {
490
- return PERMISSION;
490
+ static getPermissionFromSettings(freeze = true) {
491
+ return freeze ? PERMISSION : Permission.clone(PERMISSION);
491
492
  }
492
493
  restartable = true;
493
494
  modules = new Set();
@@ -1001,7 +1002,7 @@ class ClientDb extends Client {
1001
1002
  }
1002
1003
  }
1003
1004
  static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
1004
- if (!credential) {
1005
+ if (!credential || !Array.isArray(result)) {
1005
1006
  return result;
1006
1007
  }
1007
1008
  let cache, cacheDir;
@@ -1068,8 +1069,14 @@ class ClientDb extends Client {
1068
1069
  }
1069
1070
  else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
1070
1071
  const dbKey = userKey + sessionKey;
1071
- ((CACHE_SESSION[source] ||= {})[dbKey] ||= {})[queryString] = result;
1072
- setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
1072
+ const sourceData = CACHE_SESSION[source] ||= {};
1073
+ let data = sourceData[dbKey];
1074
+ if (!data) {
1075
+ data = {};
1076
+ sourceData[dbKey] = data;
1077
+ setTimeout(() => delete sourceData[dbKey], sessionExpires * 1000);
1078
+ }
1079
+ data[queryString] = result;
1073
1080
  }
1074
1081
  }
1075
1082
  return result;
@@ -1201,14 +1208,14 @@ class ClientDb extends Client {
1201
1208
  break;
1202
1209
  case 'object':
1203
1210
  if (options !== null) {
1204
- ({ value, sessionKey, renewCache, exclusiveOf } = options);
1211
+ ({ value, sessionKey, exclusiveOf, renewCache } = options);
1205
1212
  if (Array.isArray(exclusiveOf)) {
1206
1213
  const ignoreCache = exclusiveOf[2];
1207
1214
  if (ignoreCache === 1) {
1208
1215
  return;
1209
1216
  }
1210
1217
  renewCache ||= ignoreCache === 0;
1211
- queryString += '_' + exclusiveOf.toString();
1218
+ queryString += '_' + exclusiveOf.slice(0, 2).toString();
1212
1219
  }
1213
1220
  }
1214
1221
  break;
@@ -1221,9 +1228,10 @@ class ClientDb extends Client {
1221
1228
  }
1222
1229
  }
1223
1230
  const result = ClientDb.findResult(this.moduleName + '_' + source, uuidKey || credential, queryString, value === 0 ? 0 : ClientDb.getTimeout(value || this.settingsOf(source, 'cache')), sessionKey, renewCache);
1224
- if (!exclusiveOf || !isInvalidRange(result, exclusiveOf)) {
1225
- return result;
1231
+ if (exclusiveOf && isInvalidRange(result, exclusiveOf)) {
1232
+ return;
1226
1233
  }
1234
+ return result;
1227
1235
  }
1228
1236
  setQueryResult(source, credential, queryString, result, sessionKey) {
1229
1237
  if (!Array.isArray(result)) {
@@ -1243,7 +1251,7 @@ class ClientDb extends Client {
1243
1251
  if (isInvalidRange(result, exclusiveOf)) {
1244
1252
  return result;
1245
1253
  }
1246
- queryString += '_' + exclusiveOf.toString();
1254
+ queryString += '_' + exclusiveOf.slice(0, 2).toString();
1247
1255
  }
1248
1256
  if (uuidKey) {
1249
1257
  const cache = this.settingsKey(uuidKey, 'cache');
@@ -2017,3 +2025,4 @@ class Permission {
2017
2025
  exports.Permission = Permission;
2018
2026
  _a = Permission;
2019
2027
  PERMISSION = Host.createPermission(true, true);
2028
+ Object.freeze(PERMISSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/core",
3
- "version": "0.12.12",
3
+ "version": "0.12.14",
4
4
  "description": "Core modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/module": "0.12.12",
23
- "@e-mc/types": "0.12.12",
24
- "ipaddr.js": "^2.2.0",
22
+ "@e-mc/module": "0.12.14",
23
+ "@e-mc/types": "0.12.14",
24
+ "ipaddr.js": "^2.3.0",
25
25
  "picomatch": "^4.0.3"
26
26
  }
27
27
  }