@e-mc/core 0.10.16 → 0.10.18

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 +22 -10
  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.10.16/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.18/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
  }
@@ -230,13 +230,13 @@ NOTE: **@e-mc/core** is mostly a collection of abstract base classes which canno
230
230
 
231
231
  ## References
232
232
 
233
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/squared.d.ts
234
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/core.d.ts
235
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/db.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/dom.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/logger.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/node.d.ts
239
- - https://www.unpkg.com/@e-mc/types@0.10.16/lib/settings.d.ts
233
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/squared.d.ts
234
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/core.d.ts
235
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/db.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/dom.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/logger.d.ts
238
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/node.d.ts
239
+ - https://www.unpkg.com/@e-mc/types@0.10.18/lib/settings.d.ts
240
240
 
241
241
  ## LICENSE
242
242
 
package/index.js CHANGED
@@ -235,7 +235,7 @@ function getSettingsValue(options, name, component) {
235
235
  }
236
236
  function isInvalidRange(result, range) {
237
237
  const [lower, upper = 0] = range;
238
- return result.length <= lower || upper > 0 && result.length > upper;
238
+ return Array.isArray(result) && (result.length <= lower || upper > 0 && result.length > upper);
239
239
  }
240
240
  function asPosix(value) {
241
241
  if (module_1.PLATFORM_WIN32) {
@@ -276,6 +276,7 @@ class Host extends module_1 {
276
276
  if (permission.unc_write) {
277
277
  PERMISSION.setUNCWrite(unc_write);
278
278
  }
279
+ Object.freeze(PERMISSION);
279
280
  }
280
281
  if (perm.settings) {
281
282
  const { picomatch: pico, minimatch: mini } = perm.settings;
@@ -450,8 +451,8 @@ class Host extends module_1 {
450
451
  static getLogDelayed() {
451
452
  return HOST.LOG_DELAYED;
452
453
  }
453
- static getPermissionFromSettings() {
454
- return PERMISSION;
454
+ static getPermissionFromSettings(freeze = true) {
455
+ return freeze ? PERMISSION : Permission.clone(PERMISSION);
455
456
  }
456
457
  constructor(config = {}) {
457
458
  super();
@@ -951,6 +952,9 @@ class ClientDb extends Client {
951
952
  }
952
953
  }
953
954
  static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
955
+ if (!credential || !Array.isArray(result)) {
956
+ return result;
957
+ }
954
958
  let cache, cacheDir;
955
959
  if ((0, types_1.isObject)(sessionKey)) {
956
960
  ({ cacheDir, sessionKey, sessionExpires } = sessionKey);
@@ -1015,8 +1019,14 @@ class ClientDb extends Client {
1015
1019
  }
1016
1020
  else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
1017
1021
  const dbKey = userKey + sessionKey;
1018
- ((CACHE_SESSION[source] ||= {})[dbKey] ||= {})[queryString] = result;
1019
- setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
1022
+ const sourceData = CACHE_SESSION[source] ||= {};
1023
+ let data = sourceData[dbKey];
1024
+ if (!data) {
1025
+ data = {};
1026
+ sourceData[dbKey] = data;
1027
+ setTimeout(() => delete sourceData[dbKey], sessionExpires * 1000);
1028
+ }
1029
+ data[queryString] = result;
1020
1030
  }
1021
1031
  }
1022
1032
  return result;
@@ -1145,14 +1155,14 @@ class ClientDb extends Client {
1145
1155
  break;
1146
1156
  case 'object':
1147
1157
  if (options !== null) {
1148
- ({ value, sessionKey, renewCache, exclusiveOf } = options);
1158
+ ({ value, sessionKey, exclusiveOf, renewCache } = options);
1149
1159
  if (Array.isArray(exclusiveOf)) {
1150
1160
  const ignoreCache = exclusiveOf[2];
1151
1161
  if (ignoreCache === 1) {
1152
1162
  return;
1153
1163
  }
1154
1164
  renewCache ||= ignoreCache === 0;
1155
- queryString += '_' + exclusiveOf.toString();
1165
+ queryString += '_' + exclusiveOf.slice(0, 2).toString();
1156
1166
  }
1157
1167
  }
1158
1168
  break;
@@ -1165,9 +1175,10 @@ class ClientDb extends Client {
1165
1175
  }
1166
1176
  }
1167
1177
  const result = ClientDb.findResult(this.moduleName + '_' + source, uuidKey || credential, queryString, value === 0 ? 0 : ClientDb.getTimeout(value || this.settingsOf(source, 'cache')), sessionKey, renewCache);
1168
- if (!exclusiveOf || !isInvalidRange(result, exclusiveOf)) {
1169
- return result;
1178
+ if (exclusiveOf && isInvalidRange(result, exclusiveOf)) {
1179
+ return;
1170
1180
  }
1181
+ return result;
1171
1182
  }
1172
1183
  setQueryResult(source, credential, queryString, result, sessionKey) {
1173
1184
  if (!Array.isArray(result)) {
@@ -1187,7 +1198,7 @@ class ClientDb extends Client {
1187
1198
  if (isInvalidRange(result, exclusiveOf)) {
1188
1199
  return result;
1189
1200
  }
1190
- queryString += '_' + exclusiveOf.toString();
1201
+ queryString += '_' + exclusiveOf.slice(0, 2).toString();
1191
1202
  }
1192
1203
  if (uuidKey) {
1193
1204
  const cache = this.settingsKey(uuidKey, 'cache');
@@ -1452,3 +1463,4 @@ class Permission {
1452
1463
  exports.Permission = Permission;
1453
1464
  _f = kDiskRead, _g = kDiskWrite, _h = kUncRead, _j = kUncWrite;
1454
1465
  PERMISSION = Host.createPermission(true, true);
1466
+ Object.freeze(PERMISSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/core",
3
- "version": "0.10.16",
3
+ "version": "0.10.18",
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.10.16",
24
- "@e-mc/types": "0.10.16",
23
+ "@e-mc/module": "0.10.18",
24
+ "@e-mc/types": "0.10.18",
25
25
  "picomatch": "^4.0.3"
26
26
  }
27
27
  }