@e-mc/core 0.9.24 → 0.9.26

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 +19 -7
  3. package/package.json +3 -3
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.9.24/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.26/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, LogStatus } from "./squared";
@@ -67,7 +67,7 @@ interface HostConstructor extends ModuleConstructor {
67
67
  getThreadCount(full: true): ThreadCountStat;
68
68
  getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
69
69
  getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
70
- getPermissionFromSettings(): IPermission;
70
+ getPermissionFromSettings(freeze?: boolean): IPermission;
71
71
  readonly prototype: IHost;
72
72
  new(config?: HostInitConfig): IHost;
73
73
  }
@@ -229,13 +229,13 @@ NOTE: **@e-mc/core** is mostly a collection of abstract base classes which canno
229
229
 
230
230
  ## References
231
231
 
232
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/squared.d.ts
233
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/core.d.ts
234
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/db.d.ts
235
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/dom.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/logger.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/node.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.9.24/lib/settings.d.ts
232
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/squared.d.ts
233
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/core.d.ts
234
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/db.d.ts
235
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/dom.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/logger.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/node.d.ts
238
+ - https://www.unpkg.com/@e-mc/types@0.9.26/lib/settings.d.ts
239
239
 
240
240
  ## LICENSE
241
241
 
package/index.js CHANGED
@@ -212,7 +212,7 @@ function updateHostQueue(host, position, priority, broadcast) {
212
212
  }
213
213
  function isInvalidRange(result, range) {
214
214
  const [lower, upper = 0] = range;
215
- return result.length <= lower || upper > 0 && result.length > upper;
215
+ return Array.isArray(result) && (result.length <= lower || upper > 0 && result.length > upper);
216
216
  }
217
217
  function asPosix(value) {
218
218
  if (PLATFORM_WIN32) {
@@ -253,6 +253,7 @@ class Host extends module_1 {
253
253
  if (permission.unc_write) {
254
254
  PERMISSION.setUNCWrite(unc_write);
255
255
  }
256
+ Object.freeze(PERMISSION);
256
257
  }
257
258
  if ((0, types_1.isObject)(perm.settings)) {
258
259
  const { picomatch: pico, minimatch: mini } = perm.settings;
@@ -424,8 +425,8 @@ class Host extends module_1 {
424
425
  }
425
426
  return count;
426
427
  }
427
- static getPermissionFromSettings() {
428
- return PERMISSION;
428
+ static getPermissionFromSettings(freeze = true) {
429
+ return freeze ? PERMISSION : Permission.clone(PERMISSION);
429
430
  }
430
431
  constructor(config = {}) {
431
432
  super();
@@ -879,6 +880,9 @@ class ClientDb extends Client {
879
880
  }
880
881
  }
881
882
  static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
883
+ if (!credential || !Array.isArray(result)) {
884
+ return result;
885
+ }
882
886
  let cache, cacheDir;
883
887
  if ((0, types_1.isObject)(sessionKey)) {
884
888
  ({ cacheDir, sessionKey, sessionExpires } = sessionKey);
@@ -943,8 +947,14 @@ class ClientDb extends Client {
943
947
  }
944
948
  else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
945
949
  const dbKey = userKey + sessionKey;
946
- ((CACHE_SESSION[source] ||= {})[dbKey] ||= {})[queryString] = result;
947
- setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
950
+ const sourceData = CACHE_SESSION[source] ||= {};
951
+ let data = sourceData[dbKey];
952
+ if (!data) {
953
+ data = {};
954
+ sourceData[dbKey] = data;
955
+ setTimeout(() => delete sourceData[dbKey], sessionExpires * 1000);
956
+ }
957
+ data[queryString] = result;
948
958
  }
949
959
  }
950
960
  return result;
@@ -1093,9 +1103,10 @@ class ClientDb extends Client {
1093
1103
  }
1094
1104
  }
1095
1105
  const result = ClientDb.findResult(this.moduleName + '_' + source, uuidKey || credential, queryString, value === 0 ? 0 : ClientDb.getTimeout(value || this.settingsOf(source, 'cache')), sessionKey, renewCache);
1096
- if (!exclusiveOf || !isInvalidRange(result, exclusiveOf)) {
1097
- return result;
1106
+ if (exclusiveOf && !isInvalidRange(result, exclusiveOf)) {
1107
+ return;
1098
1108
  }
1109
+ return result;
1099
1110
  }
1100
1111
  setQueryResult(source, credential, queryString, result, sessionKey) {
1101
1112
  if (!Array.isArray(result)) {
@@ -1372,3 +1383,4 @@ class Permission {
1372
1383
  exports.Permission = Permission;
1373
1384
  _f = kDiskRead, _g = kDiskWrite, _h = kUncRead, _j = kUncWrite;
1374
1385
  PERMISSION = Host.createPermission(true, true);
1386
+ Object.freeze(PERMISSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/core",
3
- "version": "0.9.24",
3
+ "version": "0.9.26",
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": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.9.24",
24
- "@e-mc/types": "0.9.24",
23
+ "@e-mc/module": "0.9.26",
24
+ "@e-mc/types": "0.9.26",
25
25
  "picomatch": "^4.0.3"
26
26
  }
27
27
  }