@e-mc/module 0.8.7 → 0.8.9
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 +3 -7
- package/README.md +7 -7
- package/index.js +36 -29
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
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.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/module
|
|
2
2
|
|
|
3
3
|
* NodeJS 14
|
|
4
|
-
*
|
|
4
|
+
* ES2019
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -232,11 +232,11 @@ interface ModuleConstructor {
|
|
|
232
232
|
|
|
233
233
|
## References
|
|
234
234
|
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
238
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/core.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/logger.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/module.d.ts
|
|
238
|
+
- https://www.unpkg.com/@e-mc/types@0.8.9/lib/node.d.ts
|
|
239
239
|
|
|
240
240
|
## LICENSE
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
MIT
|
package/index.js
CHANGED
|
@@ -212,12 +212,14 @@ function setYarnVer() {
|
|
|
212
212
|
}
|
|
213
213
|
function applyStyle(options, style) {
|
|
214
214
|
var _h;
|
|
215
|
+
var _j;
|
|
215
216
|
for (const attr in style) {
|
|
216
|
-
(_h = options)[attr]
|
|
217
|
+
(_h = (_j = options)[attr]) !== null && _h !== void 0 ? _h : (_j[attr] = style[attr]);
|
|
217
218
|
}
|
|
218
219
|
return options;
|
|
219
220
|
}
|
|
220
221
|
function checkColorOptions(type, settings, options) {
|
|
222
|
+
var _h, _j, _k, _l;
|
|
221
223
|
if (typeof settings !== 'object') {
|
|
222
224
|
return false;
|
|
223
225
|
}
|
|
@@ -231,7 +233,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
231
233
|
result = true;
|
|
232
234
|
}
|
|
233
235
|
if (typeof settings.valueBold === 'boolean') {
|
|
234
|
-
options.valueBold
|
|
236
|
+
(_h = options.valueBold) !== null && _h !== void 0 ? _h : (options.valueBold = settings.valueBold);
|
|
235
237
|
}
|
|
236
238
|
if (settings.hintColor) {
|
|
237
239
|
options.hintColor || (options.hintColor = settings.hintColor);
|
|
@@ -242,7 +244,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
242
244
|
result = true;
|
|
243
245
|
}
|
|
244
246
|
if (typeof settings.hintBold === 'boolean') {
|
|
245
|
-
options.hintBold
|
|
247
|
+
(_j = options.hintBold) !== null && _j !== void 0 ? _j : (options.hintBold = settings.hintBold);
|
|
246
248
|
}
|
|
247
249
|
if (type & types_1.LOG_TYPE.FAIL) {
|
|
248
250
|
return result;
|
|
@@ -256,7 +258,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
256
258
|
result = true;
|
|
257
259
|
}
|
|
258
260
|
if (typeof settings.titleBold === 'boolean') {
|
|
259
|
-
options.titleBold
|
|
261
|
+
(_k = options.titleBold) !== null && _k !== void 0 ? _k : (options.titleBold = settings.titleBold);
|
|
260
262
|
}
|
|
261
263
|
if (settings.messageColor) {
|
|
262
264
|
options.messageColor || (options.messageColor = settings.messageColor);
|
|
@@ -267,7 +269,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
267
269
|
result = true;
|
|
268
270
|
}
|
|
269
271
|
if (typeof settings.messageBold === 'boolean') {
|
|
270
|
-
options.messageBold
|
|
272
|
+
(_l = options.messageBold) !== null && _l !== void 0 ? _l : (options.messageBold = settings.messageBold);
|
|
271
273
|
}
|
|
272
274
|
return result;
|
|
273
275
|
}
|
|
@@ -508,6 +510,7 @@ function getCacheItem(map, key) {
|
|
|
508
510
|
return item[1];
|
|
509
511
|
}
|
|
510
512
|
function addCacheItem(map, key, data, cache) {
|
|
513
|
+
var _h;
|
|
511
514
|
const length = Buffer.byteLength(data);
|
|
512
515
|
if (length < MEMORY_CACHE_DISK.min_size || length > MEMORY_CACHE_DISK.max_size) {
|
|
513
516
|
return;
|
|
@@ -523,7 +526,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
523
526
|
cache = true;
|
|
524
527
|
}
|
|
525
528
|
}
|
|
526
|
-
if (!(cache && MEMORY_CACHE_DISK.exclude
|
|
529
|
+
if (!(cache && ((_h = MEMORY_CACHE_DISK.exclude) === null || _h === void 0 ? void 0 : _h.some(value => pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') }))))) {
|
|
527
530
|
if (!map.has(key)) {
|
|
528
531
|
++CACHE_TOTAL;
|
|
529
532
|
}
|
|
@@ -539,7 +542,7 @@ function checkFunction(value) {
|
|
|
539
542
|
}
|
|
540
543
|
function encryptMessage(data, cipher, algorithm) {
|
|
541
544
|
var _h;
|
|
542
|
-
if (cipher
|
|
545
|
+
if ((cipher === null || cipher === void 0 ? void 0 : cipher.key) && cipher.iv) {
|
|
543
546
|
algorithm || (algorithm = cipher.algorithm || 'aes-256-gcm');
|
|
544
547
|
const result = (0, types_1.encryptUTF8)(algorithm, cipher.key, cipher.iv, data);
|
|
545
548
|
if (result) {
|
|
@@ -601,7 +604,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
601
604
|
}
|
|
602
605
|
else if (options.hostPermissionOnly) {
|
|
603
606
|
const host = this.host;
|
|
604
|
-
if (host
|
|
607
|
+
if ((host === null || host === void 0 ? void 0 : host.permission) && !host[method](result)) {
|
|
605
608
|
if (options.throwsPermission) {
|
|
606
609
|
throw errorPermission(result);
|
|
607
610
|
}
|
|
@@ -617,7 +620,8 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
617
620
|
return result;
|
|
618
621
|
}
|
|
619
622
|
function applyLogId(options) {
|
|
620
|
-
|
|
623
|
+
var _h;
|
|
624
|
+
(_h = options.sessionId) !== null && _h !== void 0 ? _h : (options.sessionId = this.sessionId);
|
|
621
625
|
let value = options.broadcastId;
|
|
622
626
|
if (value === undefined) {
|
|
623
627
|
if (value = this.broadcastId) {
|
|
@@ -683,7 +687,7 @@ class Module extends EventEmitter {
|
|
|
683
687
|
this[_f] = new AbortController();
|
|
684
688
|
this[_g] = null;
|
|
685
689
|
}
|
|
686
|
-
static get VERSION() { return "0.8.
|
|
690
|
+
static get VERSION() { return "0.8.9"; }
|
|
687
691
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
688
692
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
689
693
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -764,6 +768,7 @@ class Module extends EventEmitter {
|
|
|
764
768
|
return true;
|
|
765
769
|
}
|
|
766
770
|
static formatMessage(type, title, value, message, options = {}) {
|
|
771
|
+
var _h, _j, _k, _l;
|
|
767
772
|
const error = !!message && message instanceof Error;
|
|
768
773
|
if (error && hideAbort(message)) {
|
|
769
774
|
return;
|
|
@@ -807,7 +812,7 @@ class Module extends EventEmitter {
|
|
|
807
812
|
const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
|
|
808
813
|
let output, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
|
|
809
814
|
if (Array.isArray(value)) {
|
|
810
|
-
hint = value[1]
|
|
815
|
+
hint = (_h = value[1]) !== null && _h !== void 0 ? _h : '';
|
|
811
816
|
value = value[0];
|
|
812
817
|
}
|
|
813
818
|
if (error) {
|
|
@@ -956,7 +961,7 @@ class Module extends EventEmitter {
|
|
|
956
961
|
}
|
|
957
962
|
}
|
|
958
963
|
if (bold) {
|
|
959
|
-
options.messageBold
|
|
964
|
+
(_j = options.messageBold) !== null && _j !== void 0 ? _j : (options.messageBold = true);
|
|
960
965
|
}
|
|
961
966
|
}
|
|
962
967
|
}
|
|
@@ -974,7 +979,7 @@ class Module extends EventEmitter {
|
|
|
974
979
|
}
|
|
975
980
|
if (!hintColor && !hintBgColor) {
|
|
976
981
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
977
|
-
hintBold
|
|
982
|
+
hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
|
|
978
983
|
}
|
|
979
984
|
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
980
985
|
}
|
|
@@ -990,7 +995,7 @@ class Module extends EventEmitter {
|
|
|
990
995
|
}
|
|
991
996
|
if (!valueColor && !valueBgColor) {
|
|
992
997
|
({ color: valueColor, bgColor: valueBgColor } = formatValue);
|
|
993
|
-
valueBold
|
|
998
|
+
valueBold !== null && valueBold !== void 0 ? valueBold : (valueBold = formatValue.bold);
|
|
994
999
|
}
|
|
995
1000
|
try {
|
|
996
1001
|
let v = value, i = id, m = message;
|
|
@@ -1006,9 +1011,9 @@ class Module extends EventEmitter {
|
|
|
1006
1011
|
const formatMessage = format.message;
|
|
1007
1012
|
if (!messageColor && !messageBgColor) {
|
|
1008
1013
|
({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
|
|
1009
|
-
messageBold
|
|
1014
|
+
messageBold !== null && messageBold !== void 0 ? messageBold : (messageBold = formatMessage.bold);
|
|
1010
1015
|
}
|
|
1011
|
-
messageWidth
|
|
1016
|
+
messageWidth !== null && messageWidth !== void 0 ? messageWidth : (messageWidth = formatMessage.width);
|
|
1012
1017
|
let u = unit;
|
|
1013
1018
|
if (u) {
|
|
1014
1019
|
if ((0, types_1.isObject)(SETTINGS.time_process)) {
|
|
@@ -1029,13 +1034,13 @@ class Module extends EventEmitter {
|
|
|
1029
1034
|
}
|
|
1030
1035
|
m = '';
|
|
1031
1036
|
}
|
|
1032
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold)
|
|
1037
|
+
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
|
|
1033
1038
|
}
|
|
1034
1039
|
catch {
|
|
1035
1040
|
}
|
|
1036
1041
|
}
|
|
1037
1042
|
if (!output) {
|
|
1038
|
-
const m = truncateStart(this.asString(message), options.messageWidth
|
|
1043
|
+
const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
|
|
1039
1044
|
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1040
1045
|
}
|
|
1041
1046
|
if (broadcastId) {
|
|
@@ -1571,7 +1576,7 @@ class Module extends EventEmitter {
|
|
|
1571
1576
|
}
|
|
1572
1577
|
}
|
|
1573
1578
|
if (isFile) {
|
|
1574
|
-
if (ignoreFile
|
|
1579
|
+
if (ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.test(name)) {
|
|
1575
1580
|
return ignore();
|
|
1576
1581
|
}
|
|
1577
1582
|
if (overwrite === false) {
|
|
@@ -1596,7 +1601,7 @@ class Module extends EventEmitter {
|
|
|
1596
1601
|
}));
|
|
1597
1602
|
}
|
|
1598
1603
|
else if (depth > 0 && (isDir || file.isDirectory())) {
|
|
1599
|
-
if (ignoreDir
|
|
1604
|
+
if (ignoreDir === null || ignoreDir === void 0 ? void 0 : ignoreDir.test(name)) {
|
|
1600
1605
|
return ignore();
|
|
1601
1606
|
}
|
|
1602
1607
|
recurse.call(this, paths.concat(name), depth - 1);
|
|
@@ -2172,6 +2177,7 @@ class Module extends EventEmitter {
|
|
|
2172
2177
|
}
|
|
2173
2178
|
static loadSettings(settings, password) {
|
|
2174
2179
|
var _h;
|
|
2180
|
+
var _j;
|
|
2175
2181
|
const current = VALUES["process.password"];
|
|
2176
2182
|
if (current) {
|
|
2177
2183
|
const proc = settings.process || {};
|
|
@@ -2187,7 +2193,7 @@ class Module extends EventEmitter {
|
|
|
2187
2193
|
}
|
|
2188
2194
|
}
|
|
2189
2195
|
else if ((0, types_1.isString)(password)) {
|
|
2190
|
-
VALUES["process.password"] = encryptMessage(password, settings.process
|
|
2196
|
+
VALUES["process.password"] = encryptMessage(password, (_h = settings.process) === null || _h === void 0 ? void 0 : _h.cipher);
|
|
2191
2197
|
}
|
|
2192
2198
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2193
2199
|
if ((0, types_1.isPlainObject)(node)) {
|
|
@@ -2233,10 +2239,10 @@ class Module extends EventEmitter {
|
|
|
2233
2239
|
VALUES["process.env.apply"] = env.apply;
|
|
2234
2240
|
}
|
|
2235
2241
|
if ((0, types_1.isString)(pwd)) {
|
|
2236
|
-
VALUES[
|
|
2242
|
+
VALUES[_j = "process.password"] || (VALUES[_j] = encryptMessage(pwd, cipher));
|
|
2237
2243
|
}
|
|
2238
2244
|
}
|
|
2239
|
-
if ((0, types_1.isPlainObject)(memory
|
|
2245
|
+
if ((0, types_1.isPlainObject)(memory === null || memory === void 0 ? void 0 : memory.settings)) {
|
|
2240
2246
|
const { users, cache_disk } = memory.settings;
|
|
2241
2247
|
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2242
2248
|
VALUES["memory.settings.users"] = users;
|
|
@@ -2415,7 +2421,7 @@ class Module extends EventEmitter {
|
|
|
2415
2421
|
}
|
|
2416
2422
|
}
|
|
2417
2423
|
}
|
|
2418
|
-
if (broadcast
|
|
2424
|
+
if (broadcast === null || broadcast === void 0 ? void 0 : broadcast.out) {
|
|
2419
2425
|
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
|
|
2420
2426
|
}
|
|
2421
2427
|
if (stack_trace && stack_trace !== true && +stack_trace > 0) {
|
|
@@ -2510,7 +2516,7 @@ class Module extends EventEmitter {
|
|
|
2510
2516
|
}
|
|
2511
2517
|
const host = this.host;
|
|
2512
2518
|
const item = this[kSupports][name];
|
|
2513
|
-
return host && !item
|
|
2519
|
+
return host && !(item === null || item === void 0 ? void 0 : item.modified) ? host.supports(name) : (item === null || item === void 0 ? void 0 : item.value) === true;
|
|
2514
2520
|
}
|
|
2515
2521
|
getTempDir(pathname, filename, createDir) {
|
|
2516
2522
|
let increment = 0, moduleDir, uuidDir;
|
|
@@ -2534,11 +2540,11 @@ class Module extends EventEmitter {
|
|
|
2534
2540
|
let result;
|
|
2535
2541
|
if ((0, types_1.isString)(pathname)) {
|
|
2536
2542
|
leading.push(pathname);
|
|
2537
|
-
createDir
|
|
2543
|
+
createDir !== null && createDir !== void 0 ? createDir : (createDir = true);
|
|
2538
2544
|
}
|
|
2539
2545
|
if (uuidDir) {
|
|
2540
2546
|
leading.push((0, types_1.generateUUID)());
|
|
2541
|
-
createDir
|
|
2547
|
+
createDir !== null && createDir !== void 0 ? createDir : (createDir = true);
|
|
2542
2548
|
}
|
|
2543
2549
|
if ((createDir || increment > 0) && !Module.isDir(result = path.join(...leading))) {
|
|
2544
2550
|
const [output] = tryIncrementDir(result, increment);
|
|
@@ -3496,8 +3502,9 @@ class Module extends EventEmitter {
|
|
|
3496
3502
|
return !!this[kPermission];
|
|
3497
3503
|
}
|
|
3498
3504
|
isFatal(err) {
|
|
3499
|
-
|
|
3500
|
-
|
|
3505
|
+
var _h, _j;
|
|
3506
|
+
const fatal = (_j = (_h = this.host) === null || _h === void 0 ? void 0 : _h.config.error) === null || _j === void 0 ? void 0 : _j.fatal;
|
|
3507
|
+
return fatal !== null && fatal !== void 0 ? fatal : VALUES["error.fatal"];
|
|
3501
3508
|
}
|
|
3502
3509
|
get moduleName() {
|
|
3503
3510
|
return this._moduleName;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/types": "0.8.9",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|