@e-mc/core 0.8.2 → 0.8.4

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 +174 -3
  2. package/index.js +18 -19
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -1,7 +1,178 @@
1
- ### @e-mc/core
1
+ # @e-mc/core
2
2
 
3
- https://e-mc.readthedocs.io
3
+ * NodeJS 14
4
+ * ES2020
4
5
 
5
- ### LICENSE
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { DataSource, LogStatus } from "./squared";
16
+
17
+ import type { IHost, IModule, ModuleConstructor } from "./index";
18
+ import type { CacheOptions, HostInitConfig, JoinQueueOptions, PermissionReadWrite, ResumeThreadOptions, StoreResultOptions, ThreadCountStat } from "./core";
19
+ import type { QueryResult, TimeoutAction } from "./db";
20
+ import type { AddEventListenerOptions } from "./dom";
21
+ import type { StatusType } from "./logger";
22
+ import type { Settings } from "./node";
23
+ import type { ClientDbSettings, ClientModule, ClientSettings, DbCacheValue, DbCoerceSettings, DbCoerceValue, DbSourceOptions } from "./settings";
24
+
25
+ interface IHost extends IModule {
26
+ restartable: boolean;
27
+ readonly modules: Set<IModule>;
28
+ readonly subProcesses: Set<IModule>;
29
+ readonly startTime: number;
30
+ using(...items: unknown[] | [boolean, ...unknown[]]): this;
31
+ contains(item: unknown, condition?: (...args: any[]) => boolean): boolean;
32
+ find(name: string): IModule | undefined;
33
+ findAll(name: string): IModule[];
34
+ willLog(name: string): boolean;
35
+ ignoreLog(values: boolean | string | string[]): void;
36
+ collectLog(level?: boolean): LogStatus<StatusType>[];
37
+ willAbort(value: string | IModule): boolean;
38
+ loadModule(name: string, ...args: any[]): IModule | null;
39
+ retain(process: IModule): void;
40
+ release(process: IModule, log?: boolean): boolean;
41
+ restart(...args: unknown[]): void;
42
+ joinQueue(options?: JoinQueueOptions): boolean;
43
+ resumeThread?(options: ResumeThreadOptions): void;
44
+ set host(value);
45
+ get host(): null;
46
+ get config(): Readonly<HostInitConfig>;
47
+ get errorCount(): number;
48
+ get username(): string;
49
+ set done(value);
50
+ get done(): boolean;
51
+ get queued(): boolean;
52
+ }
53
+
54
+ interface HostConstructor extends ModuleConstructor {
55
+ loadSettings(settings: Settings, password?: string): boolean;
56
+ loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
57
+ isPermission(value: unknown): value is IPermission;
58
+ createPermission(all?: boolean, freeze?: boolean): IPermission;
59
+ kill(username: string, iv: BinaryLike, all: true): number;
60
+ kill(username: string, iv: BinaryLike, pid: number | number[] | boolean): number;
61
+ getThreadCount(full: true): ThreadCountStat;
62
+ getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
63
+ getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
64
+ getPermissionFromSettings(): IPermission;
65
+ readonly prototype: IHost;
66
+ new(config?: HostInitConfig): IHost;
67
+ }
68
+
69
+ interface IClient extends IModule<IHost> {
70
+ module: ClientModule;
71
+ init(...args: unknown[]): this;
72
+ getUserSettings(): unknown;
73
+ get settings(): ClientSettings;
74
+ set cacheDir(value: string);
75
+ get cacheDir(): string;
76
+ set extensions(values: unknown[]);
77
+ get extensions(): ((...args: unknown[]) => unknown)[];
78
+ }
79
+
80
+ interface ClientConstructor extends ModuleConstructor {
81
+ readonly prototype: IClient;
82
+ new(module?: ClientModule): IClient;
83
+ }
84
+
85
+ interface IClientDb extends IClient<IHost, ClientModule<ClientDbSettings>> {
86
+ database: DataSource[];
87
+ cacheExpires: number;
88
+ add(item: DataSource, state?: number): void;
89
+ hasCache(source: string, sessionKey?: string, override?: DbCacheValue): boolean;
90
+ hasCoerce(source: string, component: keyof DbCoerceSettings, uuidKey: string | undefined): boolean;
91
+ hasCoerce(source: string, component: keyof DbCoerceSettings, override: DbCoerceValue | null | undefined, credential?: unknown): boolean;
92
+ hasCoerce(source: string, component: keyof DbCoerceSettings, credential?: unknown): boolean;
93
+ getQueryResult(source: string, credential: unknown, queryString: string, renewCache: boolean): QueryResult | undefined;
94
+ getQueryResult(source: string, credential: unknown, queryString: string, sessionKey: string, renewCache?: boolean): QueryResult | undefined;
95
+ getQueryResult(source: string, credential: unknown, queryString: string, options?: CacheOptions | string, renewCache?: boolean): QueryResult | undefined;
96
+ setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, sessionKey: string | undefined): QueryResult;
97
+ setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, options?: CacheOptions | string): QueryResult;
98
+ applyState(items: DataSource | DataSource[], value: number, as?: boolean): void;
99
+ commit(items?: DataSource[]): Promise<boolean>;
100
+ valueOfKey(credential: unknown, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
101
+ settingsOf(source: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
102
+ settingsKey(uuidKey: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
103
+ get pending(): DataSource[];
104
+ get committed(): DataSource[];
105
+ get failed(): DataSource[];
106
+ }
107
+
108
+ interface ClientDbConstructor extends ClientConstructor<IHost, ClientModule> {
109
+ STORE_RESULT_PARTITION_SIZE: number;
110
+ STORE_RESULT_PARTITION_MULT: number;
111
+ readonly TRANSACTION_ACTIVE: number;
112
+ readonly TRANSACTION_PARTIAL: number;
113
+ readonly TRANSACTION_COMMIT: number;
114
+ readonly TRANSACTION_TERMINATE: number;
115
+ readonly TRANSACTION_ABORT: number;
116
+ readonly TRANSACTION_FAIL: number;
117
+ loadSettings(settings: Pick<Settings, "process" | "memory">, password?: string) : boolean;
118
+ getTimeout(value: number | string | TimeoutAction | undefined): number;
119
+ convertTime(value: number | string): number;
120
+ findResult(source: string, credential: unknown, queryString: string, timeout: number, sessionKey?: string | boolean, renewCache?: boolean): QueryResult | undefined;
121
+ storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, options: StoreResultOptions): QueryResult;
122
+ storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, sessionKey: string, sessionExpires: number): QueryResult;
123
+ storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue): QueryResult;
124
+ storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue | undefined, options: StoreResultOptions): QueryResult;
125
+ purgeResult(prefix?: string): Promise<number>;
126
+ extractUUID(credential: unknown): string;
127
+ setPoolConfig(value: unknown): void;
128
+ getPoolConfig(source: string): unknown;
129
+ keyOfResult(source: string, credential: unknown, uuidOnly?: boolean): string;
130
+ readonly prototype: IClientDb;
131
+ new(module?: ClientModule, database?: DataSource[]): IClientDb;
132
+ }
133
+
134
+ interface IAbortComponent extends AbortController {
135
+ reset(): void;
136
+ get aborted(): boolean;
137
+ }
138
+
139
+ interface AbortComponentConstructor {
140
+ attach(instance: IAbortComponent, signal: AbortSignal, options?: AddEventListenerOptions): void;
141
+ detach(instance: IAbortComponent, signal: AbortSignal): void;
142
+ readonly prototype: IAbortComponent;
143
+ new(): IAbortComponent;
144
+ }
145
+
146
+ interface IPermission {
147
+ setDiskRead(pathname?: string | string[], enabled?: boolean): void;
148
+ setDiskWrite(pathname?: string | string[], enabled?: boolean): void;
149
+ setUNCRead(pathname?: string | string[], enabled?: boolean): void;
150
+ setUNCWrite(pathname?: string | string[], enabled?: boolean): void;
151
+ getDiskRead(): string | string[];
152
+ getDiskWrite(): string | string[];
153
+ getUNCRead(): string | string[];
154
+ getUNCWrite(): string | string[];
155
+ hasDiskRead(pathname: string): boolean;
156
+ hasDiskWrite(pathname: string): boolean;
157
+ hasUNCRead(pathname: string): boolean;
158
+ hasUNCWrite(pathname: string): boolean;
159
+ get diskRead(): boolean;
160
+ get diskWrite(): boolean;
161
+ get uncRead(): boolean;
162
+ get uncWrite(): boolean;
163
+ }
164
+ ```
165
+
166
+ ## References
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
175
+
176
+ ## LICENSE
6
177
 
7
178
  BSD 3-Clause
package/index.js CHANGED
@@ -1,5 +1,5 @@
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");
@@ -10,7 +10,6 @@ const module_1 = require("../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');
@@ -45,6 +44,7 @@ const HOST = {
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 };
@@ -442,10 +442,9 @@ class Host extends module_1.default {
442
442
  this._usingObjects = new Set();
443
443
  this[_a] = false;
444
444
  this[_b] = false;
445
- this[_c] = '';
446
445
  const { broadcastId, log, username, priority } = config;
447
446
  if ((0, types_1.isString)(username)) {
448
- this[kUsername] = username;
447
+ HOST_USERNAME.set(this, username);
449
448
  }
450
449
  if (broadcastId) {
451
450
  this.broadcastId = broadcastId;
@@ -636,7 +635,7 @@ class Host extends module_1.default {
636
635
  return this[kConfig];
637
636
  }
638
637
  get username() {
639
- return this[kUsername];
638
+ return HOST_USERNAME.get(this) || '';
640
639
  }
641
640
  set done(value) {
642
641
  if (value) {
@@ -655,7 +654,7 @@ class Host extends module_1.default {
655
654
  }
656
655
  }
657
656
  exports.Host = Host;
658
- _a = kDone, _b = kQueued, _c = kUsername;
657
+ _a = kDone, _b = kQueued;
659
658
  class Client extends module_1.default {
660
659
  static async purgeMemory(percent = 1, limit = 0, parent) {
661
660
  return parent ? super.purgeMemory(percent, limit) : 0;
@@ -663,7 +662,7 @@ class Client extends module_1.default {
663
662
  constructor(data) {
664
663
  super();
665
664
  this._extensions = null;
666
- this[_d] = '';
665
+ this[_c] = '';
667
666
  this.module = (0, types_1.isPlainObject)(data) ? data : {};
668
667
  }
669
668
  init(...args) {
@@ -697,8 +696,8 @@ class Client extends module_1.default {
697
696
  return this[kCacheDir];
698
697
  }
699
698
  get settings() {
700
- var _k;
701
- return ((_k = this.module).settings || (_k.settings = {}));
699
+ var _j;
700
+ return ((_j = this.module).settings || (_j.settings = {}));
702
701
  }
703
702
  set extensions(values) {
704
703
  if (Array.isArray(values)) {
@@ -711,7 +710,7 @@ class Client extends module_1.default {
711
710
  }
712
711
  }
713
712
  exports.Client = Client;
714
- _d = kCacheDir;
713
+ _c = kCacheDir;
715
714
  class ClientDb extends Client {
716
715
  static get TRANSACTION_ACTIVE() { return 1 /* DB_TRANSACTION.ACTIVE */; }
717
716
  static get TRANSACTION_PARTIAL() { return 2 /* DB_TRANSACTION.PARTIAL */; }
@@ -836,7 +835,7 @@ class ClientDb extends Client {
836
835
  }
837
836
  }
838
837
  static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
839
- var _k, _l;
838
+ var _j, _k;
840
839
  let cache, cacheDir;
841
840
  if ((0, types_1.isObject)(sessionKey)) {
842
841
  ({ cacheDir, sessionKey, sessionExpires } = sessionKey);
@@ -879,7 +878,7 @@ class ClientDb extends Client {
879
878
  queryString = this.asHash(queryString);
880
879
  if (timeout > 0) {
881
880
  const item = [expireTime(timeout), result, Date.now(), 0];
882
- ((_k = (CACHE_USER[source] || (CACHE_USER[source] = {})))[userKey] || (_k[userKey] = {}))[queryString] = item;
881
+ ((_j = (CACHE_USER[source] || (CACHE_USER[source] = {})))[userKey] || (_j[userKey] = {}))[queryString] = item;
883
882
  addSourceResult(source, item);
884
883
  if (cacheDir) {
885
884
  if (partition) {
@@ -901,7 +900,7 @@ class ClientDb extends Client {
901
900
  }
902
901
  else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
903
902
  const dbKey = userKey + sessionKey;
904
- ((_l = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_l[dbKey] = {}))[queryString] = result;
903
+ ((_k = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_k[dbKey] = {}))[queryString] = result;
905
904
  setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000 /* TIME.S */);
906
905
  }
907
906
  }
@@ -1133,8 +1132,8 @@ class ClientDb extends Client {
1133
1132
  }
1134
1133
  }
1135
1134
  settingsKey(uuidKey, name, component) {
1136
- var _k;
1137
- const data = ((_k = this.settings).user_key || (_k.user_key = {}))[uuidKey];
1135
+ var _j;
1136
+ const data = ((_j = this.settings).user_key || (_j.user_key = {}))[uuidKey];
1138
1137
  if ((0, types_1.isObject)(data)) {
1139
1138
  return getSettingsValue(data, name, component);
1140
1139
  }
@@ -1157,7 +1156,7 @@ ClientDb.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_
1157
1156
  ClientDb.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_MULT */;
1158
1157
  class AbortComponent {
1159
1158
  constructor() {
1160
- this[_e] = new AbortController();
1159
+ this[_d] = new AbortController();
1161
1160
  }
1162
1161
  static attach(instance, signal, options) {
1163
1162
  let map = ABORT_LISTENER.get(instance);
@@ -1197,7 +1196,7 @@ class AbortComponent {
1197
1196
  }
1198
1197
  }
1199
1198
  exports.AbortComponent = AbortComponent;
1200
- _e = kAbortHandler;
1199
+ _d = kAbortHandler;
1201
1200
  class Permission {
1202
1201
  static create(settings, parent, freeze) {
1203
1202
  if (this.validate(settings)) {
@@ -1286,10 +1285,10 @@ class Permission {
1286
1285
  return '';
1287
1286
  }
1288
1287
  constructor(freeze = false) {
1288
+ this[_e] = { enabled: null, value: '' };
1289
1289
  this[_f] = { enabled: null, value: '' };
1290
1290
  this[_g] = { enabled: null, value: '' };
1291
1291
  this[_h] = { enabled: null, value: '' };
1292
- this[_j] = { enabled: null, value: '' };
1293
1292
  this[kFreeze] = freeze;
1294
1293
  }
1295
1294
  setDiskRead(pathname = '', enabled = true) {
@@ -1342,5 +1341,5 @@ class Permission {
1342
1341
  }
1343
1342
  }
1344
1343
  exports.Permission = Permission;
1345
- _f = kDiskRead, _g = kDiskWrite, _h = kUncRead, _j = kUncWrite;
1344
+ _e = kDiskRead, _f = kDiskWrite, _g = kUncRead, _h = kUncWrite;
1346
1345
  PERMISSION = Host.createPermission(true, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/core",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
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": [
@@ -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.2",
24
- "@e-mc/types": "0.8.2",
23
+ "@e-mc/module": "0.8.4",
24
+ "@e-mc/types": "0.8.4",
25
25
  "picomatch": "^3.0.1"
26
26
  }
27
27
  }