@e-mc/core 0.8.7 → 0.9.0
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.
- package/LICENSE +10 -10
- package/README.md +99 -19
- package/index.d.ts +12 -12
- package/index.js +84 -57
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/core
|
|
2
2
|
|
|
3
|
-
* NodeJS 14
|
|
3
|
+
* NodeJS 14/16
|
|
4
4
|
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.0/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { DataSource, LogStatus } from "./squared";
|
|
@@ -18,7 +18,7 @@ import type { IHost, IModule, ModuleConstructor } from "./index";
|
|
|
18
18
|
import type { CacheOptions, HostInitConfig, JoinQueueOptions, PermissionReadWrite, ResumeThreadOptions, StoreResultOptions, ThreadCountStat } from "./core";
|
|
19
19
|
import type { QueryResult, TimeoutAction } from "./db";
|
|
20
20
|
import type { AddEventListenerOptions } from "./dom";
|
|
21
|
-
import type { StatusType } from "./logger";
|
|
21
|
+
import type { LogState, StatusType } from "./logger";
|
|
22
22
|
import type { Settings } from "./node";
|
|
23
23
|
import type { ClientDbSettings, ClientModule, ClientSettings, DbCacheValue, DbCoerceSettings, DbCoerceValue, DbSourceOptions } from "./settings";
|
|
24
24
|
|
|
@@ -34,21 +34,27 @@ interface IHost extends IModule {
|
|
|
34
34
|
willLog(name: string): boolean;
|
|
35
35
|
ignoreLog(values: boolean | string | string[]): void;
|
|
36
36
|
collectLog(level?: boolean): LogStatus<StatusType>[];
|
|
37
|
+
pauseLog(): void;
|
|
38
|
+
resumeLog(): void;
|
|
39
|
+
hasLog(type: string): boolean;
|
|
40
|
+
delayMessage(...args: unknown[]): void;
|
|
37
41
|
willAbort(value: string | IModule): boolean;
|
|
38
42
|
loadModule(name: string, ...args: any[]): IModule | null;
|
|
39
43
|
retain(process: IModule): void;
|
|
40
44
|
release(process: IModule, log?: boolean): boolean;
|
|
41
45
|
restart(...args: unknown[]): void;
|
|
42
46
|
joinQueue(options?: JoinQueueOptions): boolean;
|
|
47
|
+
updateProgress(name: string, ...args: unknown[]): void;
|
|
43
48
|
resumeThread?(options: ResumeThreadOptions): void;
|
|
44
49
|
set host(value);
|
|
45
50
|
get host(): null;
|
|
46
51
|
get config(): Readonly<HostInitConfig>;
|
|
47
|
-
get errorCount(): number;
|
|
48
52
|
get username(): string;
|
|
49
53
|
set done(value);
|
|
50
54
|
get done(): boolean;
|
|
51
55
|
get queued(): boolean;
|
|
56
|
+
get logState(): LogState;
|
|
57
|
+
get errorCount(): number;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
interface HostConstructor extends ModuleConstructor {
|
|
@@ -57,7 +63,7 @@ interface HostConstructor extends ModuleConstructor {
|
|
|
57
63
|
isPermission(value: unknown): value is IPermission;
|
|
58
64
|
createPermission(all?: boolean, freeze?: boolean): IPermission;
|
|
59
65
|
kill(username: string, iv: BinaryLike, all: true): number;
|
|
60
|
-
kill(username: string, iv: BinaryLike, pid: number | number[]
|
|
66
|
+
kill(username: string, iv: BinaryLike, pid: number | number[]): number;
|
|
61
67
|
getThreadCount(full: true): ThreadCountStat;
|
|
62
68
|
getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
|
|
63
69
|
getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
|
|
@@ -86,15 +92,14 @@ interface IClientDb extends IClient<IHost, ClientModule<ClientDbSettings>> {
|
|
|
86
92
|
database: DataSource[];
|
|
87
93
|
cacheExpires: number;
|
|
88
94
|
add(item: DataSource, state?: number): void;
|
|
89
|
-
hasCache(source: string, sessionKey?: string
|
|
90
|
-
hasCoerce(source: string, component: keyof DbCoerceSettings, uuidKey: string
|
|
91
|
-
hasCoerce(source: string, component: keyof DbCoerceSettings, override: DbCoerceValue | null | undefined, credential?: unknown): boolean;
|
|
95
|
+
hasCache(source: string, sessionKey?: string): boolean;
|
|
96
|
+
hasCoerce(source: string, component: keyof DbCoerceSettings, uuidKey: Undef<string>): boolean;
|
|
92
97
|
hasCoerce(source: string, component: keyof DbCoerceSettings, credential?: unknown): boolean;
|
|
93
98
|
getQueryResult(source: string, credential: unknown, queryString: string, renewCache: boolean): QueryResult | undefined;
|
|
94
|
-
getQueryResult(source: string, credential: unknown, queryString: string, sessionKey
|
|
95
|
-
getQueryResult(source: string, credential: unknown, queryString: string, options?: CacheOptions
|
|
96
|
-
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, sessionKey
|
|
97
|
-
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, options?: CacheOptions
|
|
99
|
+
getQueryResult(source: string, credential: unknown, queryString: string, sessionKey?: string, renewCache?: boolean): QueryResult | undefined;
|
|
100
|
+
getQueryResult(source: string, credential: unknown, queryString: string, options?: CacheOptions, renewCache?: boolean): QueryResult | undefined;
|
|
101
|
+
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, sessionKey?: string): QueryResult;
|
|
102
|
+
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, options?: CacheOptions): QueryResult;
|
|
98
103
|
applyState(items: DataSource | DataSource[], value: number, as?: boolean): void;
|
|
99
104
|
commit(items?: DataSource[]): Promise<boolean>;
|
|
100
105
|
valueOfKey(credential: unknown, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
@@ -163,15 +168,90 @@ interface IPermission {
|
|
|
163
168
|
}
|
|
164
169
|
```
|
|
165
170
|
|
|
171
|
+
## Settings
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import type { ExecOptions } from "./settings";
|
|
175
|
+
|
|
176
|
+
import type { MinimatchOptions } from "minimatch";
|
|
177
|
+
import type { PicomatchOptions } from "picomatch";
|
|
178
|
+
|
|
179
|
+
interface ProcessModule {
|
|
180
|
+
thread?: {
|
|
181
|
+
admin: {
|
|
182
|
+
users?: string[];
|
|
183
|
+
private?: boolean;
|
|
184
|
+
};
|
|
185
|
+
queue?: {
|
|
186
|
+
limit?: number;
|
|
187
|
+
expires?: number | string;
|
|
188
|
+
priority: {
|
|
189
|
+
bypass?: number;
|
|
190
|
+
min?: number;
|
|
191
|
+
max?: number;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
limit?: number;
|
|
195
|
+
expires?: number | string;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface PermissionModule {
|
|
200
|
+
disk_read?: string | string[];
|
|
201
|
+
disk_write?: string | string[];
|
|
202
|
+
unc_read?: string | string[];
|
|
203
|
+
unc_write?: string | string[];
|
|
204
|
+
settings?: {
|
|
205
|
+
broadcast_id?: string | string[];
|
|
206
|
+
picomatch?: PicomatchOptions | null;
|
|
207
|
+
minimatch?: MinimatchOptions | null;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Example usage
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
const { Host } = require("@e-mc/core");
|
|
216
|
+
|
|
217
|
+
Host.loadSettings({ // Global
|
|
218
|
+
process: {
|
|
219
|
+
thread: { limit: 8 }
|
|
220
|
+
},
|
|
221
|
+
permission: {
|
|
222
|
+
disk_read: ["**/*"],
|
|
223
|
+
disk_write: ["/tmp/**"]
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
NOTE: **@e-mc/core** is mostly a collection of abstract base classes which cannot be instantiated. **Host** is more commonly called through [@e-mc/file-manager](https://www.npmjs.com/package/@e-mc/file-manager).
|
|
229
|
+
|
|
230
|
+
## NodeJS 14 LTS
|
|
231
|
+
|
|
232
|
+
Any optional fail safe dependencies were removed as of `E-mc 0.9`. The code itself will still be *ES2020* and will continue to work equivalently when self-installing these dependencies:
|
|
233
|
+
|
|
234
|
+
### Under 15.4 + 16.0
|
|
235
|
+
|
|
236
|
+
```sh
|
|
237
|
+
npm i abort-controller event-target-shim
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Under 14.17 + 15.6
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
npm i uuid
|
|
244
|
+
```
|
|
245
|
+
|
|
166
246
|
## References
|
|
167
247
|
|
|
168
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
169
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
170
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
171
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
172
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
173
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
174
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
248
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/squared.d.ts
|
|
249
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/core.d.ts
|
|
250
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/db.d.ts
|
|
251
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/dom.d.ts
|
|
252
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/logger.d.ts
|
|
253
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/node.d.ts
|
|
254
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/settings.d.ts
|
|
175
255
|
|
|
176
256
|
## LICENSE
|
|
177
257
|
|
package/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { HostConstructor, ModuleConstructor } from '../types/lib';
|
|
2
|
-
import type { AbortComponentConstructor, ClientConstructor, ClientDbConstructor, PermissionConstructor } from '../types/lib/core';
|
|
3
|
-
|
|
4
|
-
declare namespace core {
|
|
5
|
-
const Module: ModuleConstructor;
|
|
6
|
-
const Host: HostConstructor;
|
|
7
|
-
const Client: ClientConstructor;
|
|
8
|
-
const ClientDb: ClientDbConstructor;
|
|
9
|
-
const AbortComponent: AbortComponentConstructor;
|
|
10
|
-
const Permission: PermissionConstructor;
|
|
11
|
-
}
|
|
12
|
-
|
|
1
|
+
import type { HostConstructor, ModuleConstructor } from '../types/lib';
|
|
2
|
+
import type { AbortComponentConstructor, ClientConstructor, ClientDbConstructor, PermissionConstructor } from '../types/lib/core';
|
|
3
|
+
|
|
4
|
+
declare namespace core {
|
|
5
|
+
const Module: ModuleConstructor;
|
|
6
|
+
const Host: HostConstructor;
|
|
7
|
+
const Client: ClientConstructor;
|
|
8
|
+
const ClientDb: ClientDbConstructor;
|
|
9
|
+
const AbortComponent: AbortComponentConstructor;
|
|
10
|
+
const Permission: PermissionConstructor;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
13
|
export = core;
|
package/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
4
3
|
exports.Module = exports.Permission = exports.AbortComponent = exports.ClientDb = exports.Client = exports.Host = void 0;
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const fs = require("fs");
|
|
7
6
|
const pm = require("picomatch");
|
|
8
7
|
const types_1 = require("@e-mc/types");
|
|
9
8
|
const module_1 = require("@e-mc/module");
|
|
10
|
-
exports.Module = module_1
|
|
9
|
+
exports.Module = module_1;
|
|
11
10
|
const kConfig = Symbol('config');
|
|
12
11
|
const kQueued = Symbol('queued');
|
|
13
12
|
const kAbortHandler = Symbol('abortHandler');
|
|
14
13
|
const kFreeze = Symbol('freeze');
|
|
15
14
|
const kDone = Symbol('done');
|
|
15
|
+
const kLogState = Symbol('logState');
|
|
16
16
|
const kCacheDir = Symbol('cacheDir');
|
|
17
17
|
const kDiskRead = Symbol('diskRead');
|
|
18
18
|
const kDiskWrite = Symbol('diskWrite');
|
|
@@ -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, ...module_1.
|
|
81
|
+
instance.writeTimeElapsed('JOIN', ['Thread restarting...', HOST.THREAD_LIMIT > 1 ? 'Availability: ' + HOST.DONE.size + ' / ' + HOST.THREAD_LIMIT : ''], startTime, { type: 2, ...module_1.LOG_STYLE_WARN });
|
|
82
82
|
}
|
|
83
83
|
queueMicrotask(() => {
|
|
84
84
|
try {
|
|
@@ -126,7 +126,7 @@ function getFunctions(values) {
|
|
|
126
126
|
for (const value of values) {
|
|
127
127
|
let method = null;
|
|
128
128
|
if (typeof value === 'string') {
|
|
129
|
-
method = module_1.
|
|
129
|
+
method = module_1.parseFunction(value, { external: true, absolute: true, sync: true });
|
|
130
130
|
}
|
|
131
131
|
else if (typeof value === 'function') {
|
|
132
132
|
method = value;
|
|
@@ -198,13 +198,7 @@ function addHostQueue(item) {
|
|
|
198
198
|
if (!au && bu) {
|
|
199
199
|
return 1;
|
|
200
200
|
}
|
|
201
|
-
|
|
202
|
-
return -1;
|
|
203
|
-
}
|
|
204
|
-
if (b.priority < a.priority) {
|
|
205
|
-
return 1;
|
|
206
|
-
}
|
|
207
|
-
return 0;
|
|
201
|
+
return a.priority - b.priority;
|
|
208
202
|
});
|
|
209
203
|
}
|
|
210
204
|
function resumeHostQueue(host) {
|
|
@@ -213,7 +207,7 @@ function resumeHostQueue(host) {
|
|
|
213
207
|
}
|
|
214
208
|
function updateHostQueue(host, position, priority, broadcast) {
|
|
215
209
|
if (!broadcast || host.broadcastId) {
|
|
216
|
-
host.formatMessage(2, 'QUEUE', ["Thread limit exceeded" + ` (position #${position + 1})`, host.username], 'Priority: ' + priority, { type: 2, ...module_1.
|
|
210
|
+
host.formatMessage(2, 'QUEUE', ["Thread limit exceeded" + ` (position #${position + 1})`, host.username], 'Priority: ' + priority, { type: 2, ...module_1.LOG_STYLE_WARN });
|
|
217
211
|
}
|
|
218
212
|
}
|
|
219
213
|
function isInvalidRange(result, range) {
|
|
@@ -227,7 +221,7 @@ function asPosix(value) {
|
|
|
227
221
|
const readable = (value) => (0, types_1.isString)(value) || (0, types_1.isArray)(value);
|
|
228
222
|
const expireTime = (value) => Date.now() + value * 1000;
|
|
229
223
|
const convertSeconds = (value) => typeof value === 'string' && Math.ceil((0, types_1.parseTime)(value) / 1000) || 0;
|
|
230
|
-
class Host extends module_1
|
|
224
|
+
class Host extends module_1 {
|
|
231
225
|
static async purgeMemory(percent = 1, limit = 0, parent) {
|
|
232
226
|
return parent ? super.purgeMemory(percent, limit) : 0;
|
|
233
227
|
}
|
|
@@ -439,9 +433,11 @@ class Host extends module_1.default {
|
|
|
439
433
|
this._threadable = true;
|
|
440
434
|
this._logExclude = false;
|
|
441
435
|
this._logLevel = 0;
|
|
436
|
+
this._logDelayed = null;
|
|
442
437
|
this._usingObjects = new Set();
|
|
443
438
|
this[_a] = false;
|
|
444
439
|
this[_b] = false;
|
|
440
|
+
this[_c] = 1;
|
|
445
441
|
const { broadcastId, log, username, priority } = config;
|
|
446
442
|
if ((0, types_1.isString)(username)) {
|
|
447
443
|
HOST_USERNAME.set(this, username);
|
|
@@ -451,7 +447,7 @@ class Host extends module_1.default {
|
|
|
451
447
|
}
|
|
452
448
|
if (log !== undefined) {
|
|
453
449
|
if ((0, types_1.isPlainObject)(log)) {
|
|
454
|
-
const { enabled, level, exclude, useColor } = log;
|
|
450
|
+
const { enabled, level, exclude, useColor, showProgress } = log;
|
|
455
451
|
if (level !== undefined) {
|
|
456
452
|
this.logLevel = level;
|
|
457
453
|
}
|
|
@@ -464,6 +460,9 @@ class Host extends module_1.default {
|
|
|
464
460
|
if (useColor) {
|
|
465
461
|
this.supports('stripAnsi', false);
|
|
466
462
|
}
|
|
463
|
+
if (showProgress) {
|
|
464
|
+
this._logDelayed = [];
|
|
465
|
+
}
|
|
467
466
|
}
|
|
468
467
|
else {
|
|
469
468
|
this.ignoreLog(typeof log === 'boolean' ? !log : log);
|
|
@@ -483,6 +482,7 @@ class Host extends module_1.default {
|
|
|
483
482
|
}
|
|
484
483
|
}
|
|
485
484
|
restart(...args) { }
|
|
485
|
+
updateProgress(name, ...args) { }
|
|
486
486
|
isFatal(err) {
|
|
487
487
|
const fatal = this.config.error?.fatal;
|
|
488
488
|
return fatal ?? super.isFatal(err);
|
|
@@ -546,10 +546,12 @@ class Host extends module_1.default {
|
|
|
546
546
|
values = [values];
|
|
547
547
|
}
|
|
548
548
|
if (Array.isArray(values)) {
|
|
549
|
-
if (
|
|
550
|
-
this._logExclude
|
|
549
|
+
if (Array.isArray(this._logExclude)) {
|
|
550
|
+
this._logExclude.push(...values);
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
this._logExclude = values.slice(0);
|
|
551
554
|
}
|
|
552
|
-
this._logExclude.push(...values);
|
|
553
555
|
this._logEnabled = this.willLog(this.moduleName);
|
|
554
556
|
}
|
|
555
557
|
else if (values) {
|
|
@@ -576,6 +578,42 @@ class Host extends module_1.default {
|
|
|
576
578
|
result.sort(level ? (a, b) => b.type - a.type : (a, b) => a.timeStamp - b.timeStamp);
|
|
577
579
|
return result;
|
|
578
580
|
}
|
|
581
|
+
hasLog(type) {
|
|
582
|
+
switch (type) {
|
|
583
|
+
case 'progress':
|
|
584
|
+
return this._logDelayed !== null;
|
|
585
|
+
default:
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
pauseLog() {
|
|
590
|
+
if (this._logDelayed) {
|
|
591
|
+
this[kLogState] = 0;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
resumeLog() {
|
|
595
|
+
const delayed = this._logDelayed;
|
|
596
|
+
if (delayed) {
|
|
597
|
+
const trailing = {};
|
|
598
|
+
for (const args of delayed) {
|
|
599
|
+
if (typeof args[4].progressBar !== 'boolean') {
|
|
600
|
+
module_1.formatMessage(...args);
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
trailing[args[1]] = args;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
for (const title in trailing) {
|
|
607
|
+
const args = trailing[title];
|
|
608
|
+
delete args[4].progressBar;
|
|
609
|
+
module_1.formatMessage(...args);
|
|
610
|
+
}
|
|
611
|
+
this[kLogState] = 1;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
delayMessage(args) {
|
|
615
|
+
this._logDelayed?.push(args);
|
|
616
|
+
}
|
|
579
617
|
retain(process) {
|
|
580
618
|
this.subProcesses.add(process);
|
|
581
619
|
process.host = this;
|
|
@@ -649,20 +687,23 @@ class Host extends module_1.default {
|
|
|
649
687
|
get queued() {
|
|
650
688
|
return this[kQueued];
|
|
651
689
|
}
|
|
690
|
+
get logState() {
|
|
691
|
+
return this[kLogState];
|
|
692
|
+
}
|
|
652
693
|
get errorCount() {
|
|
653
694
|
return Array.from(this.modules).reduce((a, b) => a + b.errors.length, this.errors.length);
|
|
654
695
|
}
|
|
655
696
|
}
|
|
656
697
|
exports.Host = Host;
|
|
657
|
-
_a = kDone, _b = kQueued;
|
|
658
|
-
class Client extends module_1
|
|
698
|
+
_a = kDone, _b = kQueued, _c = kLogState;
|
|
699
|
+
class Client extends module_1 {
|
|
659
700
|
static async purgeMemory(percent = 1, limit = 0, parent) {
|
|
660
701
|
return parent ? super.purgeMemory(percent, limit) : 0;
|
|
661
702
|
}
|
|
662
703
|
constructor(data) {
|
|
663
704
|
super();
|
|
664
705
|
this._extensions = null;
|
|
665
|
-
this[
|
|
706
|
+
this[_d] = '';
|
|
666
707
|
this.module = (0, types_1.isPlainObject)(data) ? data : {};
|
|
667
708
|
}
|
|
668
709
|
init(...args) {
|
|
@@ -688,7 +729,7 @@ class Client extends module_1.default {
|
|
|
688
729
|
return username && (0, types_1.isPlainObject)(result = this.settings.users?.[username]) ? result : null;
|
|
689
730
|
}
|
|
690
731
|
set cacheDir(value) {
|
|
691
|
-
if (path.isAbsolute(value) && module_1.
|
|
732
|
+
if (path.isAbsolute(value) && module_1.isDir(value)) {
|
|
692
733
|
this[kCacheDir] = value;
|
|
693
734
|
}
|
|
694
735
|
}
|
|
@@ -696,8 +737,8 @@ class Client extends module_1.default {
|
|
|
696
737
|
return this[kCacheDir];
|
|
697
738
|
}
|
|
698
739
|
get settings() {
|
|
699
|
-
var
|
|
700
|
-
return ((
|
|
740
|
+
var _k;
|
|
741
|
+
return ((_k = this.module).settings || (_k.settings = {}));
|
|
701
742
|
}
|
|
702
743
|
set extensions(values) {
|
|
703
744
|
if (Array.isArray(values)) {
|
|
@@ -710,7 +751,7 @@ class Client extends module_1.default {
|
|
|
710
751
|
}
|
|
711
752
|
}
|
|
712
753
|
exports.Client = Client;
|
|
713
|
-
|
|
754
|
+
_d = kCacheDir;
|
|
714
755
|
class ClientDb extends Client {
|
|
715
756
|
static get TRANSACTION_ACTIVE() { return 1; }
|
|
716
757
|
static get TRANSACTION_PARTIAL() { return 2; }
|
|
@@ -835,7 +876,7 @@ class ClientDb extends Client {
|
|
|
835
876
|
}
|
|
836
877
|
}
|
|
837
878
|
static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
|
|
838
|
-
var
|
|
879
|
+
var _k, _l;
|
|
839
880
|
let cache, cacheDir;
|
|
840
881
|
if ((0, types_1.isObject)(sessionKey)) {
|
|
841
882
|
({ cacheDir, sessionKey, sessionExpires } = sessionKey);
|
|
@@ -860,7 +901,7 @@ class ClientDb extends Client {
|
|
|
860
901
|
case 'object': {
|
|
861
902
|
let seconds, dir;
|
|
862
903
|
({ timeout: seconds, when_empty: whenEmpty, dir } = cache);
|
|
863
|
-
if ((0, types_1.isString)(dir) && (!cacheDir || module_1.
|
|
904
|
+
if ((0, types_1.isString)(dir) && (!cacheDir || module_1.isDir(dir))) {
|
|
864
905
|
cacheDir = dir;
|
|
865
906
|
partition = true;
|
|
866
907
|
}
|
|
@@ -878,7 +919,7 @@ class ClientDb extends Client {
|
|
|
878
919
|
queryString = this.asHash(queryString);
|
|
879
920
|
if (timeout > 0) {
|
|
880
921
|
const item = [expireTime(timeout), result, Date.now(), 0];
|
|
881
|
-
((
|
|
922
|
+
((_k = (CACHE_USER[source] || (CACHE_USER[source] = {})))[userKey] || (_k[userKey] = {}))[queryString] = item;
|
|
882
923
|
addSourceResult(source, item);
|
|
883
924
|
if (cacheDir) {
|
|
884
925
|
if (partition) {
|
|
@@ -900,7 +941,7 @@ class ClientDb extends Client {
|
|
|
900
941
|
}
|
|
901
942
|
else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
|
|
902
943
|
const dbKey = userKey + sessionKey;
|
|
903
|
-
((
|
|
944
|
+
((_l = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_l[dbKey] = {}))[queryString] = result;
|
|
904
945
|
setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
|
|
905
946
|
}
|
|
906
947
|
}
|
|
@@ -1001,33 +1042,20 @@ class ClientDb extends Client {
|
|
|
1001
1042
|
this.database.push(item);
|
|
1002
1043
|
}
|
|
1003
1044
|
}
|
|
1004
|
-
hasCache(source, sessionKey
|
|
1005
|
-
return (0, types_1.isString)(sessionKey) || ClientDb.getTimeout(
|
|
1045
|
+
hasCache(source, sessionKey) {
|
|
1046
|
+
return (0, types_1.isString)(sessionKey) || ClientDb.getTimeout(this.settingsOf(source, 'cache')) > 0;
|
|
1006
1047
|
}
|
|
1007
|
-
hasCoerce(source, component,
|
|
1008
|
-
if (override) {
|
|
1009
|
-
if (typeof override === 'string') {
|
|
1010
|
-
credential = override;
|
|
1011
|
-
override = undefined;
|
|
1012
|
-
}
|
|
1013
|
-
else if (!credential && (0, types_1.isPlainObject)(override) && 'uuidKey' in override) {
|
|
1014
|
-
credential = override.uuidKey;
|
|
1015
|
-
override = undefined;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1048
|
+
hasCoerce(source, component, credential) {
|
|
1018
1049
|
let uuidKey;
|
|
1019
1050
|
if (credential && ((0, types_1.validateUUID)(credential) ? uuidKey = credential : uuidKey = ClientDb.extractUUID(credential))) {
|
|
1020
1051
|
const value = this.settingsKey(uuidKey, 'coerce', component);
|
|
1021
1052
|
if (value !== undefined) {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
if ((0, types_1.isPlainObject)(override) && (override = override[component]) !== undefined) {
|
|
1030
|
-
return override === true;
|
|
1053
|
+
if (typeof value === 'boolean') {
|
|
1054
|
+
return value && component === 'options';
|
|
1055
|
+
}
|
|
1056
|
+
if ((0, types_1.isPlainObject)(value) && component in value) {
|
|
1057
|
+
return value[component] === true;
|
|
1058
|
+
}
|
|
1031
1059
|
}
|
|
1032
1060
|
}
|
|
1033
1061
|
return this.settingsOf(source, 'coerce', component) === true || component === 'options' && this.settingsOf(source, 'coerce') === true;
|
|
@@ -1132,8 +1160,7 @@ class ClientDb extends Client {
|
|
|
1132
1160
|
}
|
|
1133
1161
|
}
|
|
1134
1162
|
settingsKey(uuidKey, name, component) {
|
|
1135
|
-
|
|
1136
|
-
const data = ((_j = this.settings).user_key || (_j.user_key = {}))[uuidKey];
|
|
1163
|
+
const data = this.settings.user_key?.[uuidKey];
|
|
1137
1164
|
if ((0, types_1.isObject)(data)) {
|
|
1138
1165
|
return getSettingsValue(data, name, component);
|
|
1139
1166
|
}
|
|
@@ -1156,7 +1183,7 @@ ClientDb.STORE_RESULT_PARTITION_SIZE = 16;
|
|
|
1156
1183
|
ClientDb.STORE_RESULT_PARTITION_MULT = 2;
|
|
1157
1184
|
class AbortComponent {
|
|
1158
1185
|
constructor() {
|
|
1159
|
-
this[
|
|
1186
|
+
this[_e] = new AbortController();
|
|
1160
1187
|
}
|
|
1161
1188
|
static attach(instance, signal, options) {
|
|
1162
1189
|
let map = ABORT_LISTENER.get(instance);
|
|
@@ -1196,7 +1223,7 @@ class AbortComponent {
|
|
|
1196
1223
|
}
|
|
1197
1224
|
}
|
|
1198
1225
|
exports.AbortComponent = AbortComponent;
|
|
1199
|
-
|
|
1226
|
+
_e = kAbortHandler;
|
|
1200
1227
|
class Permission {
|
|
1201
1228
|
static create(settings, parent, freeze) {
|
|
1202
1229
|
if (this.validate(settings)) {
|
|
@@ -1285,10 +1312,10 @@ class Permission {
|
|
|
1285
1312
|
return '';
|
|
1286
1313
|
}
|
|
1287
1314
|
constructor(freeze = false) {
|
|
1288
|
-
this[_e] = { enabled: null, value: '' };
|
|
1289
1315
|
this[_f] = { enabled: null, value: '' };
|
|
1290
1316
|
this[_g] = { enabled: null, value: '' };
|
|
1291
1317
|
this[_h] = { enabled: null, value: '' };
|
|
1318
|
+
this[_j] = { enabled: null, value: '' };
|
|
1292
1319
|
this[kFreeze] = freeze;
|
|
1293
1320
|
}
|
|
1294
1321
|
setDiskRead(pathname = '', enabled = true) {
|
|
@@ -1341,5 +1368,5 @@ class Permission {
|
|
|
1341
1368
|
}
|
|
1342
1369
|
}
|
|
1343
1370
|
exports.Permission = Permission;
|
|
1344
|
-
|
|
1371
|
+
_f = kDiskRead, _g = kDiskWrite, _h = kUncRead, _j = kUncWrite;
|
|
1345
1372
|
PERMISSION = Host.createPermission(true, true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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.
|
|
24
|
-
"@e-mc/types": "0.
|
|
25
|
-
"picomatch": "^
|
|
23
|
+
"@e-mc/module": "0.9.0",
|
|
24
|
+
"@e-mc/types": "0.9.0",
|
|
25
|
+
"picomatch": "^4.0.2"
|
|
26
26
|
}
|
|
27
27
|
}
|