@e-mc/core 0.8.10 → 0.9.1
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 +7 -3
- package/README.md +85 -21
- package/index.js +97 -75
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
6
|
|
|
7
|
-
|
|
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
|
+
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,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/core
|
|
2
2
|
|
|
3
|
-
* NodeJS
|
|
4
|
-
*
|
|
3
|
+
* NodeJS 16
|
|
4
|
+
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.1/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,16 +168,75 @@ 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
|
+
|
|
166
230
|
## References
|
|
167
231
|
|
|
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.
|
|
232
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/squared.d.ts
|
|
233
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/core.d.ts
|
|
234
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/db.d.ts
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/dom.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/logger.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/node.d.ts
|
|
238
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/settings.d.ts
|
|
175
239
|
|
|
176
240
|
## LICENSE
|
|
177
241
|
|
|
178
|
-
|
|
242
|
+
BSD 3-Clause
|
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;
|
|
@@ -179,7 +179,7 @@ function deleteSourceResult(source, target) {
|
|
|
179
179
|
function incrementSourceCount(source, target, cacheData, queryString) {
|
|
180
180
|
const count = ++target[3];
|
|
181
181
|
const stored = CACHE_SOURCE[source];
|
|
182
|
-
if (
|
|
182
|
+
if (stored?.config && count >= stored.config.max) {
|
|
183
183
|
clearSourceResult(target);
|
|
184
184
|
deleteSourceResult(source, target);
|
|
185
185
|
if (cacheData && queryString) {
|
|
@@ -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,10 +482,10 @@ class Host extends module_1.default {
|
|
|
483
482
|
}
|
|
484
483
|
}
|
|
485
484
|
restart(...args) { }
|
|
485
|
+
updateProgress(name, ...args) { }
|
|
486
486
|
isFatal(err) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
return fatal !== null && fatal !== void 0 ? fatal : super.isFatal(err);
|
|
487
|
+
const fatal = this.config.error?.fatal;
|
|
488
|
+
return fatal ?? super.isFatal(err);
|
|
490
489
|
}
|
|
491
490
|
using(...items) {
|
|
492
491
|
const data = this._usingObjects;
|
|
@@ -547,10 +546,12 @@ class Host extends module_1.default {
|
|
|
547
546
|
values = [values];
|
|
548
547
|
}
|
|
549
548
|
if (Array.isArray(values)) {
|
|
550
|
-
if (
|
|
551
|
-
this._logExclude
|
|
549
|
+
if (Array.isArray(this._logExclude)) {
|
|
550
|
+
this._logExclude.push(...values);
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
this._logExclude = values.slice(0);
|
|
552
554
|
}
|
|
553
|
-
this._logExclude.push(...values);
|
|
554
555
|
this._logEnabled = this.willLog(this.moduleName);
|
|
555
556
|
}
|
|
556
557
|
else if (values) {
|
|
@@ -577,6 +578,42 @@ class Host extends module_1.default {
|
|
|
577
578
|
result.sort(level ? (a, b) => b.type - a.type : (a, b) => a.timeStamp - b.timeStamp);
|
|
578
579
|
return result;
|
|
579
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
|
+
}
|
|
580
617
|
retain(process) {
|
|
581
618
|
this.subProcesses.add(process);
|
|
582
619
|
process.host = this;
|
|
@@ -650,28 +687,30 @@ class Host extends module_1.default {
|
|
|
650
687
|
get queued() {
|
|
651
688
|
return this[kQueued];
|
|
652
689
|
}
|
|
690
|
+
get logState() {
|
|
691
|
+
return this[kLogState];
|
|
692
|
+
}
|
|
653
693
|
get errorCount() {
|
|
654
694
|
return Array.from(this.modules).reduce((a, b) => a + b.errors.length, this.errors.length);
|
|
655
695
|
}
|
|
656
696
|
}
|
|
657
697
|
exports.Host = Host;
|
|
658
|
-
_a = kDone, _b = kQueued;
|
|
659
|
-
class Client extends module_1
|
|
698
|
+
_a = kDone, _b = kQueued, _c = kLogState;
|
|
699
|
+
class Client extends module_1 {
|
|
660
700
|
static async purgeMemory(percent = 1, limit = 0, parent) {
|
|
661
701
|
return parent ? super.purgeMemory(percent, limit) : 0;
|
|
662
702
|
}
|
|
663
703
|
constructor(data) {
|
|
664
704
|
super();
|
|
665
705
|
this._extensions = null;
|
|
666
|
-
this[
|
|
706
|
+
this[_d] = '';
|
|
667
707
|
this.module = (0, types_1.isPlainObject)(data) ? data : {};
|
|
668
708
|
}
|
|
669
709
|
init(...args) {
|
|
670
|
-
var _j;
|
|
671
710
|
const { permission, extensions } = this.module;
|
|
672
711
|
const cache_dir = this.settings.cache_dir;
|
|
673
712
|
if (permission) {
|
|
674
|
-
const result = Permission.create(permission, permission.inherit !== false ?
|
|
713
|
+
const result = Permission.create(permission, permission.inherit !== false ? this.host?.permission : null, true);
|
|
675
714
|
if (result) {
|
|
676
715
|
this.permission = result;
|
|
677
716
|
}
|
|
@@ -685,13 +724,12 @@ class Client extends module_1.default {
|
|
|
685
724
|
return this;
|
|
686
725
|
}
|
|
687
726
|
getUserSettings() {
|
|
688
|
-
|
|
689
|
-
const username = (_j = this.host) === null || _j === void 0 ? void 0 : _j.username;
|
|
727
|
+
const username = this.host?.username;
|
|
690
728
|
let result;
|
|
691
|
-
return username && (0, types_1.isPlainObject)(result =
|
|
729
|
+
return username && (0, types_1.isPlainObject)(result = this.settings.users?.[username]) ? result : null;
|
|
692
730
|
}
|
|
693
731
|
set cacheDir(value) {
|
|
694
|
-
if (path.isAbsolute(value) && module_1.
|
|
732
|
+
if (path.isAbsolute(value) && module_1.isDir(value)) {
|
|
695
733
|
this[kCacheDir] = value;
|
|
696
734
|
}
|
|
697
735
|
}
|
|
@@ -699,8 +737,8 @@ class Client extends module_1.default {
|
|
|
699
737
|
return this[kCacheDir];
|
|
700
738
|
}
|
|
701
739
|
get settings() {
|
|
702
|
-
var
|
|
703
|
-
return ((
|
|
740
|
+
var _k;
|
|
741
|
+
return ((_k = this.module).settings || (_k.settings = {}));
|
|
704
742
|
}
|
|
705
743
|
set extensions(values) {
|
|
706
744
|
if (Array.isArray(values)) {
|
|
@@ -713,7 +751,7 @@ class Client extends module_1.default {
|
|
|
713
751
|
}
|
|
714
752
|
}
|
|
715
753
|
exports.Client = Client;
|
|
716
|
-
|
|
754
|
+
_d = kCacheDir;
|
|
717
755
|
class ClientDb extends Client {
|
|
718
756
|
static get TRANSACTION_ACTIVE() { return 1; }
|
|
719
757
|
static get TRANSACTION_PARTIAL() { return 2; }
|
|
@@ -794,14 +832,13 @@ class ClientDb extends Client {
|
|
|
794
832
|
return result > 0 ? result : 0;
|
|
795
833
|
}
|
|
796
834
|
static findResult(source, credential, queryString, timeout, sessionKey, renewCache) {
|
|
797
|
-
var _j, _k, _l;
|
|
798
835
|
const userKey = this.extractUUID(credential) || this.asHash(this.asString(credential));
|
|
799
836
|
if (!userKey) {
|
|
800
837
|
return;
|
|
801
838
|
}
|
|
802
839
|
queryString = this.asHash(queryString);
|
|
803
840
|
if (timeout > 0) {
|
|
804
|
-
const userCache =
|
|
841
|
+
const userCache = CACHE_USER[source]?.[userKey];
|
|
805
842
|
let stored;
|
|
806
843
|
if (!(userCache && (stored = userCache[queryString]))) {
|
|
807
844
|
return;
|
|
@@ -835,11 +872,11 @@ class ClientDb extends Client {
|
|
|
835
872
|
delete userCache[queryString];
|
|
836
873
|
}
|
|
837
874
|
else if (sessionKey) {
|
|
838
|
-
return
|
|
875
|
+
return CACHE_SESSION[source]?.[userKey + sessionKey]?.[queryString];
|
|
839
876
|
}
|
|
840
877
|
}
|
|
841
878
|
static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
|
|
842
|
-
var
|
|
879
|
+
var _k, _l;
|
|
843
880
|
let cache, cacheDir;
|
|
844
881
|
if ((0, types_1.isObject)(sessionKey)) {
|
|
845
882
|
({ cacheDir, sessionKey, sessionExpires } = sessionKey);
|
|
@@ -864,7 +901,7 @@ class ClientDb extends Client {
|
|
|
864
901
|
case 'object': {
|
|
865
902
|
let seconds, dir;
|
|
866
903
|
({ timeout: seconds, when_empty: whenEmpty, dir } = cache);
|
|
867
|
-
if ((0, types_1.isString)(dir) && (!cacheDir || module_1.
|
|
904
|
+
if ((0, types_1.isString)(dir) && (!cacheDir || module_1.isDir(dir))) {
|
|
868
905
|
cacheDir = dir;
|
|
869
906
|
partition = true;
|
|
870
907
|
}
|
|
@@ -882,7 +919,7 @@ class ClientDb extends Client {
|
|
|
882
919
|
queryString = this.asHash(queryString);
|
|
883
920
|
if (timeout > 0) {
|
|
884
921
|
const item = [expireTime(timeout), result, Date.now(), 0];
|
|
885
|
-
((
|
|
922
|
+
((_k = (CACHE_USER[source] || (CACHE_USER[source] = {})))[userKey] || (_k[userKey] = {}))[queryString] = item;
|
|
886
923
|
addSourceResult(source, item);
|
|
887
924
|
if (cacheDir) {
|
|
888
925
|
if (partition) {
|
|
@@ -904,7 +941,7 @@ class ClientDb extends Client {
|
|
|
904
941
|
}
|
|
905
942
|
else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
|
|
906
943
|
const dbKey = userKey + sessionKey;
|
|
907
|
-
((
|
|
944
|
+
((_l = (CACHE_SESSION[source] || (CACHE_SESSION[source] = {})))[dbKey] || (_l[dbKey] = {}))[queryString] = result;
|
|
908
945
|
setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
|
|
909
946
|
}
|
|
910
947
|
}
|
|
@@ -1005,33 +1042,20 @@ class ClientDb extends Client {
|
|
|
1005
1042
|
this.database.push(item);
|
|
1006
1043
|
}
|
|
1007
1044
|
}
|
|
1008
|
-
hasCache(source, sessionKey
|
|
1009
|
-
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;
|
|
1010
1047
|
}
|
|
1011
|
-
hasCoerce(source, component,
|
|
1012
|
-
if (override) {
|
|
1013
|
-
if (typeof override === 'string') {
|
|
1014
|
-
credential = override;
|
|
1015
|
-
override = undefined;
|
|
1016
|
-
}
|
|
1017
|
-
else if (!credential && (0, types_1.isPlainObject)(override) && 'uuidKey' in override) {
|
|
1018
|
-
credential = override.uuidKey;
|
|
1019
|
-
override = undefined;
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1048
|
+
hasCoerce(source, component, credential) {
|
|
1022
1049
|
let uuidKey;
|
|
1023
1050
|
if (credential && ((0, types_1.validateUUID)(credential) ? uuidKey = credential : uuidKey = ClientDb.extractUUID(credential))) {
|
|
1024
1051
|
const value = this.settingsKey(uuidKey, 'coerce', component);
|
|
1025
1052
|
if (value !== undefined) {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
}
|
|
1033
|
-
if ((0, types_1.isPlainObject)(override) && (override = override[component]) !== undefined) {
|
|
1034
|
-
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
|
+
}
|
|
1035
1059
|
}
|
|
1036
1060
|
}
|
|
1037
1061
|
return this.settingsOf(source, 'coerce', component) === true || component === 'options' && this.settingsOf(source, 'coerce') === true;
|
|
@@ -1072,7 +1096,6 @@ class ClientDb extends Client {
|
|
|
1072
1096
|
}
|
|
1073
1097
|
}
|
|
1074
1098
|
setQueryResult(source, credential, queryString, result, sessionKey) {
|
|
1075
|
-
var _j;
|
|
1076
1099
|
if (!Array.isArray(result)) {
|
|
1077
1100
|
result = result === undefined ? [] : [result];
|
|
1078
1101
|
}
|
|
@@ -1081,7 +1104,7 @@ class ClientDb extends Client {
|
|
|
1081
1104
|
}
|
|
1082
1105
|
const uuidKey = ClientDb.extractUUID(credential);
|
|
1083
1106
|
let options;
|
|
1084
|
-
if (ClientDb.enabled("memory.settings.users",
|
|
1107
|
+
if (ClientDb.enabled("memory.settings.users", this.host?.username)) {
|
|
1085
1108
|
let value, exclusiveOf;
|
|
1086
1109
|
if ((0, types_1.isObject)(sessionKey)) {
|
|
1087
1110
|
({ value, sessionKey, exclusiveOf } = sessionKey);
|
|
@@ -1137,8 +1160,7 @@ class ClientDb extends Client {
|
|
|
1137
1160
|
}
|
|
1138
1161
|
}
|
|
1139
1162
|
settingsKey(uuidKey, name, component) {
|
|
1140
|
-
|
|
1141
|
-
const data = ((_j = this.settings).user_key || (_j.user_key = {}))[uuidKey];
|
|
1163
|
+
const data = this.settings.user_key?.[uuidKey];
|
|
1142
1164
|
if ((0, types_1.isObject)(data)) {
|
|
1143
1165
|
return getSettingsValue(data, name, component);
|
|
1144
1166
|
}
|
|
@@ -1161,7 +1183,7 @@ ClientDb.STORE_RESULT_PARTITION_SIZE = 16;
|
|
|
1161
1183
|
ClientDb.STORE_RESULT_PARTITION_MULT = 2;
|
|
1162
1184
|
class AbortComponent {
|
|
1163
1185
|
constructor() {
|
|
1164
|
-
this[
|
|
1186
|
+
this[_e] = new AbortController();
|
|
1165
1187
|
}
|
|
1166
1188
|
static attach(instance, signal, options) {
|
|
1167
1189
|
let map = ABORT_LISTENER.get(instance);
|
|
@@ -1201,7 +1223,7 @@ class AbortComponent {
|
|
|
1201
1223
|
}
|
|
1202
1224
|
}
|
|
1203
1225
|
exports.AbortComponent = AbortComponent;
|
|
1204
|
-
|
|
1226
|
+
_e = kAbortHandler;
|
|
1205
1227
|
class Permission {
|
|
1206
1228
|
static create(settings, parent, freeze) {
|
|
1207
1229
|
if (this.validate(settings)) {
|
|
@@ -1219,28 +1241,28 @@ class Permission {
|
|
|
1219
1241
|
result.setDiskRead(disk_read);
|
|
1220
1242
|
valid = true;
|
|
1221
1243
|
}
|
|
1222
|
-
else if (parent
|
|
1244
|
+
else if (parent?.diskRead) {
|
|
1223
1245
|
result.setDiskRead(parent.getDiskRead());
|
|
1224
1246
|
}
|
|
1225
1247
|
if (readable(disk_write) && (!parent || parent.diskWrite)) {
|
|
1226
1248
|
result.setDiskWrite(disk_write);
|
|
1227
1249
|
valid = true;
|
|
1228
1250
|
}
|
|
1229
|
-
else if (parent
|
|
1251
|
+
else if (parent?.diskWrite) {
|
|
1230
1252
|
result.setDiskWrite(parent.getDiskWrite());
|
|
1231
1253
|
}
|
|
1232
1254
|
if (readable(unc_read) && (!parent || parent.uncRead)) {
|
|
1233
1255
|
result.setUNCRead(unc_read);
|
|
1234
1256
|
valid = true;
|
|
1235
1257
|
}
|
|
1236
|
-
else if (parent
|
|
1258
|
+
else if (parent?.uncRead) {
|
|
1237
1259
|
result.setUNCRead(parent.getUNCRead());
|
|
1238
1260
|
}
|
|
1239
1261
|
if (readable(unc_write) && (!parent || parent.uncWrite)) {
|
|
1240
1262
|
result.setUNCWrite(unc_write);
|
|
1241
1263
|
valid = true;
|
|
1242
1264
|
}
|
|
1243
|
-
else if (parent
|
|
1265
|
+
else if (parent?.uncWrite) {
|
|
1244
1266
|
result.setUNCWrite(parent.getUNCWrite());
|
|
1245
1267
|
}
|
|
1246
1268
|
if (valid) {
|
|
@@ -1290,10 +1312,10 @@ class Permission {
|
|
|
1290
1312
|
return '';
|
|
1291
1313
|
}
|
|
1292
1314
|
constructor(freeze = false) {
|
|
1293
|
-
this[_e] = { enabled: null, value: '' };
|
|
1294
1315
|
this[_f] = { enabled: null, value: '' };
|
|
1295
1316
|
this[_g] = { enabled: null, value: '' };
|
|
1296
1317
|
this[_h] = { enabled: null, value: '' };
|
|
1318
|
+
this[_j] = { enabled: null, value: '' };
|
|
1297
1319
|
this[kFreeze] = freeze;
|
|
1298
1320
|
}
|
|
1299
1321
|
setDiskRead(pathname = '', enabled = true) {
|
|
@@ -1346,5 +1368,5 @@ class Permission {
|
|
|
1346
1368
|
}
|
|
1347
1369
|
}
|
|
1348
1370
|
exports.Permission = Permission;
|
|
1349
|
-
|
|
1371
|
+
_f = kDiskRead, _g = kDiskWrite, _h = kUncRead, _j = kUncWrite;
|
|
1350
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.1",
|
|
4
4
|
"description": "Core modules for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
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.1",
|
|
24
|
+
"@e-mc/types": "0.9.1",
|
|
25
|
+
"picomatch": "^4.0.2"
|
|
26
26
|
}
|
|
27
27
|
}
|