@e-mc/types 0.13.9 → 0.14.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/index.js CHANGED
@@ -1,61 +1,13 @@
1
1
  "use strict";
2
- exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = exports.TRANSFER_TYPE = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_STATE = exports.LOG_TYPE = void 0;
3
- exports.createAbortError = createAbortError;
4
- exports.hasBit = hasBit;
5
- exports.ignoreFlag = ignoreFlag;
6
- exports.cloneFlag = cloneFlag;
7
- exports.usingFlag = usingFlag;
8
- exports.watchFlag = watchFlag;
9
- exports.modifiedFlag = modifiedFlag;
10
- exports.processFlag = processFlag;
11
- exports.mainFlag = mainFlag;
12
- exports.existsFlag = existsFlag;
13
- exports.getLogCurrent = getLogCurrent;
14
- exports.setLogCurrent = setLogCurrent;
15
- exports.getTempDir = getTempDir;
16
- exports.setTempDir = setTempDir;
17
- exports.isArray = isArray;
18
- exports.isPlainObject = isPlainObject;
19
- exports.isObject = isObject;
20
- exports.isString = isString;
21
- exports.isEmpty = isEmpty;
22
- exports.isFunction = isFunction;
23
- exports.isErrorCode = isErrorCode;
24
- exports.parseTime = parseTime;
25
- exports.parseExpires = parseExpires;
26
- exports.formatTime = formatTime;
27
- exports.convertTime = convertTime;
28
- exports.hasGlob = hasGlob;
29
- exports.escapePattern = escapePattern;
30
- exports.renameExt = renameExt;
31
- exports.formatSize = formatSize;
32
- exports.alignSize = alignSize;
33
- exports.cascadeObject = cascadeObject;
34
- exports.cloneObject = cloneObject;
35
- exports.coerceObject = coerceObject;
36
- exports.asFunction = asFunction;
37
- exports.getEncoding = getEncoding;
38
- exports.encryptUTF8 = encryptUTF8;
39
- exports.decryptUTF8 = decryptUTF8;
40
- exports.randomString = randomString;
41
- exports.validateUUID = validateUUID;
42
- exports.sanitizeCmd = sanitizeCmd;
43
- exports.sanitizeArgs = sanitizeArgs;
44
- exports.errorValue = errorValue;
45
- exports.errorMessage = errorMessage;
46
- exports.purgeMemory = purgeMemory;
47
- exports.incrementUUID = incrementUUID;
48
- exports.hashKey = hashKey;
49
- exports.supported = supported;
50
- exports.importESM = importESM;
51
- exports.requireESM = requireESM;
52
- const path = require("node:path");
53
- const fs = require("node:fs");
54
- const crypto = require("node:crypto");
55
- const bytes = require("bytes");
56
- const node_module_1 = require("node:module");
57
- const node_os_1 = require("node:os");
58
- const node_url_1 = require("node:url");
2
+
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
5
+ const crypto = require('node:crypto');
6
+ const util = require('node:util');
7
+ const bytes = require('bytes');
8
+ const { createRequire } = require('node:module');
9
+ const { tmpdir } = require('node:os');
10
+ const { fileURLToPath, pathToFileURL } = require('node:url');
59
11
  const PATTERN_CHARS = {
60
12
  '&': '\\x26',
61
13
  '!': '\\x21',
@@ -72,7 +24,7 @@ const PATTERN_CHARS = {
72
24
  '`': '\\x60',
73
25
  '~': '\\x7e'
74
26
  };
75
- const [VER_MAJOR, VER_MINOR, VER_PATCH] = process.version.substring(1).split('.').map(value => +value);
27
+ const [VER_MAJOR, VER_MINOR, VER_PATCH] = process.version.slice(1).split('.').map(value => +value);
76
28
  const PLATFORM_WIN32 = process.platform === 'win32';
77
29
  const REGEXP_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
78
30
  const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]*\s*\(([^)]*)\)\s*\{(.*)\})$/s;
@@ -107,7 +59,9 @@ let SUPPORTED_HASHSINGLE = false;
107
59
  let SUPPORTED_IMPORTATTRIBUTES = false;
108
60
  let SUPPORTED_REGEXPESCAPE = false;
109
61
  let SUPPORTED_FLOAT16ARRAY = false;
62
+ let SUPPORTED_ISERROR = false;
110
63
  let TEMP_DIR = path.join(process.cwd(), "tmp");
64
+ let TEMP_LOCKED = false;
111
65
  let INCREMENT_COUNT = 65536;
112
66
  let INCREMENT_PREFIX = '';
113
67
  function fromObject(value, typedArray, structured, shared) {
@@ -309,7 +263,7 @@ function parseStringDefault(value) {
309
263
  if (value.length <= 8) {
310
264
  return null;
311
265
  }
312
- switch (value.substring(0, 3)) {
266
+ switch (value.slice(0, 3)) {
313
267
  case 'new': {
314
268
  const match = REGEXP_NATIVE.exec(value.trimEnd());
315
269
  if (match) {
@@ -394,8 +348,8 @@ function checkFlags(value, flags) {
394
348
  return typeof value === 'number' && (value & flags) === flags;
395
349
  }
396
350
  const padStart = (value, char) => value > 9 ? value.toString() : char + value;
397
- const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
398
- var LOG_TYPE;
351
+ const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
352
+ exports.LOG_TYPE = void 0;
399
353
  (function (LOG_TYPE) {
400
354
  LOG_TYPE[LOG_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
401
355
  LOG_TYPE[LOG_TYPE["SYSTEM"] = 1] = "SYSTEM";
@@ -415,14 +369,15 @@ var LOG_TYPE;
415
369
  LOG_TYPE[LOG_TYPE["TIMEOUT"] = 16384] = "TIMEOUT";
416
370
  LOG_TYPE[LOG_TYPE["STDOUT"] = 32768] = "STDOUT";
417
371
  LOG_TYPE[LOG_TYPE["DB"] = 65536] = "DB";
418
- })(LOG_TYPE || (exports.LOG_TYPE = LOG_TYPE = {}));
419
- var LOG_STATE;
372
+ LOG_TYPE[LOG_TYPE["USER"] = 131072] = "USER";
373
+ })(exports.LOG_TYPE || (exports.LOG_TYPE = {}));
374
+ exports.LOG_STATE = void 0;
420
375
  (function (LOG_STATE) {
421
376
  LOG_STATE[LOG_STATE["STDIN"] = 0] = "STDIN";
422
377
  LOG_STATE[LOG_STATE["STDOUT"] = 1] = "STDOUT";
423
378
  LOG_STATE[LOG_STATE["STDERR"] = 2] = "STDERR";
424
- })(LOG_STATE || (exports.LOG_STATE = LOG_STATE = {}));
425
- var STATUS_TYPE;
379
+ })(exports.LOG_STATE || (exports.LOG_STATE = {}));
380
+ exports.STATUS_TYPE = void 0;
426
381
  (function (STATUS_TYPE) {
427
382
  STATUS_TYPE[STATUS_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
428
383
  STATUS_TYPE[STATUS_TYPE["FATAL"] = 1] = "FATAL";
@@ -432,8 +387,8 @@ var STATUS_TYPE;
432
387
  STATUS_TYPE[STATUS_TYPE["DEBUG"] = 5] = "DEBUG";
433
388
  STATUS_TYPE[STATUS_TYPE["ASSERT"] = 6] = "ASSERT";
434
389
  STATUS_TYPE[STATUS_TYPE["TRACE"] = 7] = "TRACE";
435
- })(STATUS_TYPE || (exports.STATUS_TYPE = STATUS_TYPE = {}));
436
- var FILE_TYPE;
390
+ })(exports.STATUS_TYPE || (exports.STATUS_TYPE = {}));
391
+ exports.FILE_TYPE = void 0;
437
392
  (function (FILE_TYPE) {
438
393
  FILE_TYPE[FILE_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
439
394
  FILE_TYPE[FILE_TYPE["ASSET"] = 1] = "ASSET";
@@ -441,8 +396,8 @@ var FILE_TYPE;
441
396
  FILE_TYPE[FILE_TYPE["COMPRESSED"] = 4] = "COMPRESSED";
442
397
  FILE_TYPE[FILE_TYPE["SOURCEMAP"] = 8] = "SOURCEMAP";
443
398
  FILE_TYPE[FILE_TYPE["TORRENT"] = 16] = "TORRENT";
444
- })(FILE_TYPE || (exports.FILE_TYPE = FILE_TYPE = {}));
445
- var ASSET_FLAG;
399
+ })(exports.FILE_TYPE || (exports.FILE_TYPE = {}));
400
+ exports.ASSET_FLAG = void 0;
446
401
  (function (ASSET_FLAG) {
447
402
  ASSET_FLAG[ASSET_FLAG["NONE"] = 0] = "NONE";
448
403
  ASSET_FLAG[ASSET_FLAG["IGNORE"] = 1] = "IGNORE";
@@ -453,34 +408,34 @@ var ASSET_FLAG;
453
408
  ASSET_FLAG[ASSET_FLAG["PROCESS"] = 32] = "PROCESS";
454
409
  ASSET_FLAG[ASSET_FLAG["MAIN"] = 64] = "MAIN";
455
410
  ASSET_FLAG[ASSET_FLAG["EXISTS"] = 128] = "EXISTS";
456
- })(ASSET_FLAG || (exports.ASSET_FLAG = ASSET_FLAG = {}));
457
- var ERR_CODE;
411
+ })(exports.ASSET_FLAG || (exports.ASSET_FLAG = {}));
412
+ exports.ERR_CODE = void 0;
458
413
  (function (ERR_CODE) {
459
414
  ERR_CODE["MODULE_NOT_FOUND"] = "MODULE_NOT_FOUND";
460
415
  ERR_CODE["ERR_MODULE_NOT_FOUND"] = "ERR_MODULE_NOT_FOUND";
461
- })(ERR_CODE || (exports.ERR_CODE = ERR_CODE = {}));
462
- var DOWNLOAD_TYPE;
416
+ })(exports.ERR_CODE || (exports.ERR_CODE = {}));
417
+ exports.DOWNLOAD_TYPE = void 0;
463
418
  (function (DOWNLOAD_TYPE) {
464
419
  DOWNLOAD_TYPE[DOWNLOAD_TYPE["HTTP"] = 0] = "HTTP";
465
420
  DOWNLOAD_TYPE[DOWNLOAD_TYPE["DISK"] = 1] = "DISK";
466
421
  DOWNLOAD_TYPE[DOWNLOAD_TYPE["CACHE"] = 2] = "CACHE";
467
- })(DOWNLOAD_TYPE || (exports.DOWNLOAD_TYPE = DOWNLOAD_TYPE = {}));
468
- var FETCH_TYPE;
422
+ })(exports.DOWNLOAD_TYPE || (exports.DOWNLOAD_TYPE = {}));
423
+ exports.FETCH_TYPE = void 0;
469
424
  (function (FETCH_TYPE) {
470
425
  FETCH_TYPE[FETCH_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
471
426
  FETCH_TYPE[FETCH_TYPE["HTTP"] = 1] = "HTTP";
472
427
  FETCH_TYPE[FETCH_TYPE["UNIX_SOCKET"] = 2] = "UNIX_SOCKET";
473
428
  FETCH_TYPE[FETCH_TYPE["FTP"] = 3] = "FTP";
474
429
  FETCH_TYPE[FETCH_TYPE["TORRENT"] = 4] = "TORRENT";
475
- })(FETCH_TYPE || (exports.FETCH_TYPE = FETCH_TYPE = {}));
476
- var DB_TYPE;
430
+ })(exports.FETCH_TYPE || (exports.FETCH_TYPE = {}));
431
+ exports.DB_TYPE = void 0;
477
432
  (function (DB_TYPE) {
478
433
  DB_TYPE[DB_TYPE["SQL"] = 1] = "SQL";
479
434
  DB_TYPE[DB_TYPE["NOSQL"] = 2] = "NOSQL";
480
435
  DB_TYPE[DB_TYPE["DOCUMENT"] = 4] = "DOCUMENT";
481
436
  DB_TYPE[DB_TYPE["KEYVALUE"] = 8] = "KEYVALUE";
482
- })(DB_TYPE || (exports.DB_TYPE = DB_TYPE = {}));
483
- var DB_TRANSACTION;
437
+ })(exports.DB_TYPE || (exports.DB_TYPE = {}));
438
+ exports.DB_TRANSACTION = void 0;
484
439
  (function (DB_TRANSACTION) {
485
440
  DB_TRANSACTION[DB_TRANSACTION["ACTIVE"] = 1] = "ACTIVE";
486
441
  DB_TRANSACTION[DB_TRANSACTION["PARTIAL"] = 2] = "PARTIAL";
@@ -490,35 +445,35 @@ var DB_TRANSACTION;
490
445
  DB_TRANSACTION[DB_TRANSACTION["FAIL"] = 32] = "FAIL";
491
446
  DB_TRANSACTION[DB_TRANSACTION["AUTH"] = 64] = "AUTH";
492
447
  DB_TRANSACTION[DB_TRANSACTION["CACHE"] = 128] = "CACHE";
493
- })(DB_TRANSACTION || (exports.DB_TRANSACTION = DB_TRANSACTION = {}));
494
- var TRANSFER_TYPE;
448
+ })(exports.DB_TRANSACTION || (exports.DB_TRANSACTION = {}));
449
+ exports.TRANSFER_TYPE = void 0;
495
450
  (function (TRANSFER_TYPE) {
496
451
  TRANSFER_TYPE[TRANSFER_TYPE["DISK"] = 1] = "DISK";
497
452
  TRANSFER_TYPE[TRANSFER_TYPE["STREAM"] = 2] = "STREAM";
498
453
  TRANSFER_TYPE[TRANSFER_TYPE["CHUNK"] = 4] = "CHUNK";
499
- })(TRANSFER_TYPE || (exports.TRANSFER_TYPE = TRANSFER_TYPE = {}));
500
- var WATCH_EVENT;
454
+ })(exports.TRANSFER_TYPE || (exports.TRANSFER_TYPE = {}));
455
+ exports.WATCH_EVENT = void 0;
501
456
  (function (WATCH_EVENT) {
502
457
  WATCH_EVENT["MODIFIED"] = "modified";
503
458
  WATCH_EVENT["BROADCAST"] = "broadcast";
504
459
  WATCH_EVENT["CLOSE"] = "close";
505
460
  WATCH_EVENT["ERROR"] = "error";
506
- })(WATCH_EVENT || (exports.WATCH_EVENT = WATCH_EVENT = {}));
507
- var READDIR_SORT;
461
+ })(exports.WATCH_EVENT || (exports.WATCH_EVENT = {}));
462
+ exports.READDIR_SORT = void 0;
508
463
  (function (READDIR_SORT) {
509
464
  READDIR_SORT[READDIR_SORT["FILE"] = 0] = "FILE";
510
465
  READDIR_SORT[READDIR_SORT["DIRECTORY"] = 1] = "DIRECTORY";
511
466
  READDIR_SORT[READDIR_SORT["DESCENDING"] = 2] = "DESCENDING";
512
- })(READDIR_SORT || (exports.READDIR_SORT = READDIR_SORT = {}));
513
- var THRESHOLD;
467
+ })(exports.READDIR_SORT || (exports.READDIR_SORT = {}));
468
+ exports.THRESHOLD = void 0;
514
469
  (function (THRESHOLD) {
515
470
  THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
516
471
  THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
517
472
  THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
518
473
  THRESHOLD[THRESHOLD["WATCH_RECURSIVE_CHANGE"] = 500] = "WATCH_RECURSIVE_CHANGE";
519
474
  THRESHOLD[THRESHOLD["LOGGER_METER_INCREMENT"] = 250] = "LOGGER_METER_INCREMENT";
520
- })(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
521
- exports.IMPORT_MAP = {
475
+ })(exports.THRESHOLD || (exports.THRESHOLD = {}));
476
+ const IMPORT_MAP = {
522
477
  "atlas": "@pi-r/atlas",
523
478
  "aws": "@pi-r/aws",
524
479
  "aws-v3": "@pi-r/aws-v3",
@@ -550,7 +505,7 @@ exports.IMPORT_MAP = {
550
505
  "minio": "@pi-r2/minio",
551
506
  "clean-css": "@pi-r2/clean-css",
552
507
  "csso": "@pi-r2/csso",
553
- "html-minifier": "@pi-r2/html-minifier",
508
+ "html-minifier-next": "@pi-r2/html-minifier-next",
554
509
  "html-minifier-terser": "@pi-r2/html-minifier-terser",
555
510
  "svgo": "@pi-r2/svgo",
556
511
  "uglify-js": "@pi-r2/uglify-js"
@@ -597,14 +552,20 @@ function getTempDir(...values) {
597
552
  return TEMP_DIR;
598
553
  }
599
554
  if (typeof values[0] === 'boolean' && values.shift()) {
600
- return fs.mkdtempSync(isString(values[0]) ? path.join((0, node_os_1.tmpdir)(), values[0]) : (0, node_os_1.tmpdir)() + path.sep);
555
+ return fs.mkdtempSync(isString(values[0]) ? path.join(tmpdir(), values[0]) : tmpdir() + path.sep);
601
556
  }
602
557
  return path.join(TEMP_DIR, ...values);
603
558
  }
604
- function setTempDir(value) {
559
+ function setTempDir(value, lock) {
560
+ if (TEMP_LOCKED) {
561
+ throw errorValue("Unsupported access", value);
562
+ }
605
563
  try {
606
564
  if (path.isAbsolute(value = path.normalize(value)) && fs.statSync(value).isDirectory()) {
607
565
  TEMP_DIR = value;
566
+ if (lock) {
567
+ TEMP_LOCKED = true;
568
+ }
608
569
  return true;
609
570
  }
610
571
  }
@@ -627,11 +588,20 @@ function isString(value) {
627
588
  function isEmpty(value) {
628
589
  return value === undefined || value === null || value === '' || Array.isArray(value) && value.length === 0;
629
590
  }
630
- function isFunction(value, cjs = false) {
631
- return typeof value === 'function' && (!cjs || Object.hasOwn(value, "__cjs__"));
591
+ function isFunction(value, type = false) {
592
+ if (typeof value === 'function') {
593
+ if (type) {
594
+ return type === true ? Object.hasOwn(value, "__cjs__") : Object.getOwnPropertyDescriptor(value, "__type__")?.value === type;
595
+ }
596
+ return true;
597
+ }
598
+ return false;
599
+ }
600
+ function isError(err, ...name) {
601
+ return (SUPPORTED_ISERROR ? Error.isError(err) : util.types.isNativeError(err)) && (name.length === 0 || name.some(value => value === err.name));
632
602
  }
633
603
  function isErrorCode(err, ...code) {
634
- return err instanceof Error && code.some(value => value === err.code);
604
+ return isError(err) && code.some(value => value === err.code);
635
605
  }
636
606
  function parseTime(value, start = 0) {
637
607
  if (start === true) {
@@ -800,10 +770,10 @@ function escapePattern(value, symbols) {
800
770
  }
801
771
  break;
802
772
  }
803
- result += value.substring(j, i) + ch;
773
+ result += value.slice(j, i) + ch;
804
774
  j = i + 1;
805
775
  }
806
- return j > 0 ? result + value.substring(j) : value;
776
+ return j > 0 ? result + value.slice(j) : value;
807
777
  }
808
778
  case 'number':
809
779
  return value.toString();
@@ -820,12 +790,12 @@ function renameExt(value, ext, when) {
820
790
  }
821
791
  const index = value.lastIndexOf('.');
822
792
  if (index !== -1) {
823
- const current = value.substring(index);
793
+ const current = value.slice(index);
824
794
  if (current === ext) {
825
795
  return value;
826
796
  }
827
797
  if (!when || current === when) {
828
- return value.substring(0, index) + ext;
798
+ return value.slice(0, index) + ext;
829
799
  }
830
800
  }
831
801
  return value + ext;
@@ -898,13 +868,13 @@ function cloneObject(data, options) {
898
868
  if (options === true) {
899
869
  deep = true;
900
870
  }
901
- else if (options instanceof WeakSet || options instanceof WeakMap) {
871
+ else if (options instanceof WeakMap) {
902
872
  deep = true;
903
873
  structured = true;
904
874
  deepIgnore = options;
905
875
  }
906
876
  else if (options) {
907
- ({ target, deep, deepIgnore, mergeArray, typedArray, structured, inherited, nonenumerable, symbol, preserve } = options);
877
+ ({ target, deep, deepIgnore, mergeArray, typedArray, structured, shared, inherited, nonenumerable, symbol, preserve } = options);
908
878
  if (typeof options.freezeDepth === 'number') {
909
879
  freezeDepth = options.freezeDepth - 1;
910
880
  }
@@ -918,12 +888,9 @@ function cloneObject(data, options) {
918
888
  let nested;
919
889
  if (deep || freezeDepth > 0) {
920
890
  deepIgnore ||= new WeakMap();
921
- nested = { deep, deepIgnore, freezeDepth, mergeArray, mergeDepth, typedArray, structured, preserve };
891
+ nested = { deep, deepIgnore, freezeDepth, mergeArray, mergeDepth, typedArray, structured, shared, preserve };
922
892
  }
923
893
  if (Array.isArray(data)) {
924
- if (deepIgnore instanceof WeakSet) {
925
- deepIgnore.add(data);
926
- }
927
894
  const length = data.length;
928
895
  if (Array.isArray(target)) {
929
896
  if (mergeArray && mergeDepth >= 0 && !(mergeArray === 'join' || Array.isArray(mergeArray) && mergeArray[0] === 'join')) {
@@ -941,14 +908,12 @@ function cloneObject(data, options) {
941
908
  const value = data[i];
942
909
  if (deepIgnore) {
943
910
  const found = deepIgnore.has(value);
944
- if (found && deepIgnore instanceof WeakMap) {
911
+ if (found) {
945
912
  merge = deepIgnore.get(value);
946
913
  }
947
914
  else if (!found && (Array.isArray(value) || isPlainObject(value))) {
948
915
  merge = cloneObject(value, nested);
949
- if (deepIgnore instanceof WeakMap) {
950
- deepIgnore.set(value, merge);
951
- }
916
+ deepIgnore.set(value, merge);
952
917
  }
953
918
  else {
954
919
  merge = fromObject(value, typedArray, structured, shared);
@@ -961,9 +926,6 @@ function cloneObject(data, options) {
961
926
  }
962
927
  }
963
928
  else if (isObject(data)) {
964
- if (deepIgnore instanceof WeakSet) {
965
- deepIgnore.add(data);
966
- }
967
929
  if (!isObject(target)) {
968
930
  target = {};
969
931
  }
@@ -972,14 +934,12 @@ function cloneObject(data, options) {
972
934
  let merge;
973
935
  if (deepIgnore) {
974
936
  const found = deepIgnore.has(value);
975
- if (found && deepIgnore instanceof WeakMap) {
937
+ if (found) {
976
938
  merge = deepIgnore.get(value);
977
939
  }
978
940
  else if (!found && (Array.isArray(value) || isPlainObject(value))) {
979
941
  merge = cloneObject(value, nested);
980
- if (deepIgnore instanceof WeakMap) {
981
- deepIgnore.set(value, merge);
982
- }
942
+ deepIgnore.set(value, merge);
983
943
  }
984
944
  else {
985
945
  merge = fromObject(value, typedArray, structured, shared);
@@ -1060,6 +1020,9 @@ function asFunction(value, sync = true) {
1060
1020
  }
1061
1021
  return null;
1062
1022
  }
1023
+ function asExt(value) {
1024
+ return path.extname(value).slice(1).toLowerCase();
1025
+ }
1063
1026
  function getEncoding(value, fallback) {
1064
1027
  if (typeof value === 'string') {
1065
1028
  const result = value.trim().toLowerCase();
@@ -1078,6 +1041,22 @@ function getEncoding(value, fallback) {
1078
1041
  }
1079
1042
  return fallback || 'utf8';
1080
1043
  }
1044
+ function getAlgorithm(value, fallback) {
1045
+ if (isString(value)) {
1046
+ switch (value = value.toLowerCase()) {
1047
+ case 'md5':
1048
+ case 'sha1':
1049
+ case 'sha224':
1050
+ case 'sha256':
1051
+ case 'sha384':
1052
+ case 'sha512':
1053
+ case 'ripemd':
1054
+ case 'ripemd-160':
1055
+ return value;
1056
+ }
1057
+ }
1058
+ return fallback;
1059
+ }
1081
1060
  function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
1082
1061
  if (checkCipherType(algorithm) && isString(data)) {
1083
1062
  let result;
@@ -1105,13 +1084,13 @@ function decryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
1105
1084
  }
1106
1085
  }
1107
1086
  function randomString(format, dictionary) {
1108
- if (format !== '8-4-4-4-12' || dictionary) {
1087
+ if (dictionary || format.toLowerCase() !== 'uuidv4' && format !== '8-4-4-4-12') {
1109
1088
  const match = format.match(/(\d+|[^\d]+)/g);
1110
1089
  if (match) {
1111
1090
  dictionary ||= '0123456789abcdef';
1112
1091
  const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g)?.reduce((a, b) => {
1113
1092
  let length = 0, available;
1114
- if (b.startsWith('[') && b.endsWith(']')) {
1093
+ if (b[0] === '[' && b.at(-1) === ']') {
1115
1094
  length = 1;
1116
1095
  available = b.slice(1, -1);
1117
1096
  }
@@ -1147,7 +1126,7 @@ function validateUUID(value) {
1147
1126
  }
1148
1127
  function sanitizeCmd(value, ...args) {
1149
1128
  if (value.includes(' ')) {
1150
- value = PLATFORM_WIN32 ? wrapQuote(value) : value.replaceAll(' ', '\\ ');
1129
+ value = PLATFORM_WIN32 ? wrapQuote(value) : value.replace(/ /g, '\\ ');
1151
1130
  }
1152
1131
  if (args.length === 0) {
1153
1132
  return value;
@@ -1184,7 +1163,7 @@ function sanitizeArgs(values, doubleQuote) {
1184
1163
  }
1185
1164
  else if (!quoted) {
1186
1165
  if (REGEXP_CLIESCAPE.test(value)) {
1187
- value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replaceAll("'", "'\\''")}'`;
1166
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replace(/'/g, "'\\''")}'`;
1188
1167
  }
1189
1168
  else if (RESERVED_SHELL.includes(value)) {
1190
1169
  value = `'${value}'`;
@@ -1224,11 +1203,11 @@ function purgeMemory(percent) {
1224
1203
  function incrementUUID(restart) {
1225
1204
  if (restart || INCREMENT_COUNT === 65536) {
1226
1205
  INCREMENT_COUNT = 0;
1227
- INCREMENT_PREFIX = crypto.randomUUID().substring(0, 33);
1206
+ INCREMENT_PREFIX = crypto.randomUUID().slice(0, 33);
1228
1207
  }
1229
1208
  return INCREMENT_PREFIX + (INCREMENT_COUNT++).toString(16).padStart(4, '0');
1230
1209
  }
1231
- function hashKey(data, algorithm = 'md5', encoding = 'base64') {
1210
+ function hashKey(data, algorithm = 'sha256', encoding = 'base64') {
1232
1211
  try {
1233
1212
  return SUPPORTED_HASHSINGLE ? crypto.hash(algorithm, data, encoding) : crypto.createHash(algorithm).update(data).digest(encoding);
1234
1213
  }
@@ -1258,10 +1237,10 @@ function supported(major, minor = 0, patch = 0, lts = false) {
1258
1237
  async function importESM(name, isDefault, fromPath) {
1259
1238
  let options;
1260
1239
  if (name instanceof URL) {
1261
- name = (0, node_url_1.fileURLToPath)(name);
1240
+ name = fileURLToPath(name);
1262
1241
  }
1263
1242
  else if (fromPath && path.isAbsolute(name)) {
1264
- name = (0, node_url_1.pathToFileURL)(name).toString();
1243
+ name = pathToFileURL(name).toString();
1265
1244
  }
1266
1245
  if (isObject(isDefault)) {
1267
1246
  options = isDefault;
@@ -1280,9 +1259,64 @@ async function importESM(name, isDefault, fromPath) {
1280
1259
  return result;
1281
1260
  }
1282
1261
  function requireESM(name, url, expect) {
1283
- const result = url ? (0, node_module_1.createRequire)(url)(name) : require(name);
1262
+ const result = url ? createRequire(url)(name) : require(name);
1284
1263
  return process.features.require_module && isObject(result) && result.__esModule && 'default' in result && (!expect || typeof result.default === expect) ? result.default : result;
1285
1264
  }
1286
1265
  SUPPORTED_HASHSINGLE = supported(20, 12, true) || supported(21, 7);
1287
1266
  SUPPORTED_IMPORTATTRIBUTES = supported(18, 20, true) || supported(20, 10);
1288
1267
  SUPPORTED_REGEXPESCAPE = SUPPORTED_FLOAT16ARRAY = supported(24);
1268
+ SUPPORTED_ISERROR = supported(24, 3);
1269
+
1270
+ exports.IMPORT_MAP = IMPORT_MAP;
1271
+ exports.alignSize = alignSize;
1272
+ exports.asExt = asExt;
1273
+ exports.asFunction = asFunction;
1274
+ exports.cascadeObject = cascadeObject;
1275
+ exports.cloneFlag = cloneFlag;
1276
+ exports.cloneObject = cloneObject;
1277
+ exports.coerceObject = coerceObject;
1278
+ exports.convertTime = convertTime;
1279
+ exports.createAbortError = createAbortError;
1280
+ exports.decryptUTF8 = decryptUTF8;
1281
+ exports.encryptUTF8 = encryptUTF8;
1282
+ exports.errorMessage = errorMessage;
1283
+ exports.errorValue = errorValue;
1284
+ exports.escapePattern = escapePattern;
1285
+ exports.existsFlag = existsFlag;
1286
+ exports.formatSize = formatSize;
1287
+ exports.formatTime = formatTime;
1288
+ exports.getAlgorithm = getAlgorithm;
1289
+ exports.getEncoding = getEncoding;
1290
+ exports.getLogCurrent = getLogCurrent;
1291
+ exports.getTempDir = getTempDir;
1292
+ exports.hasBit = hasBit;
1293
+ exports.hasGlob = hasGlob;
1294
+ exports.hashKey = hashKey;
1295
+ exports.ignoreFlag = ignoreFlag;
1296
+ exports.importESM = importESM;
1297
+ exports.incrementUUID = incrementUUID;
1298
+ exports.isArray = isArray;
1299
+ exports.isEmpty = isEmpty;
1300
+ exports.isError = isError;
1301
+ exports.isErrorCode = isErrorCode;
1302
+ exports.isFunction = isFunction;
1303
+ exports.isObject = isObject;
1304
+ exports.isPlainObject = isPlainObject;
1305
+ exports.isString = isString;
1306
+ exports.mainFlag = mainFlag;
1307
+ exports.modifiedFlag = modifiedFlag;
1308
+ exports.parseExpires = parseExpires;
1309
+ exports.parseTime = parseTime;
1310
+ exports.processFlag = processFlag;
1311
+ exports.purgeMemory = purgeMemory;
1312
+ exports.randomString = randomString;
1313
+ exports.renameExt = renameExt;
1314
+ exports.requireESM = requireESM;
1315
+ exports.sanitizeArgs = sanitizeArgs;
1316
+ exports.sanitizeCmd = sanitizeCmd;
1317
+ exports.setLogCurrent = setLogCurrent;
1318
+ exports.setTempDir = setTempDir;
1319
+ exports.supported = supported;
1320
+ exports.usingFlag = usingFlag;
1321
+ exports.validateUUID = validateUUID;
1322
+ exports.watchFlag = watchFlag;
package/lib/asset.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { BundleAction, FileAsset, LocationUri, MimeTypeAction } from './squared';
2
2
 
3
- import type { IFileManager, IModule } from './index';
3
+ import type { IHost, IModule } from './index';
4
4
  import type { IAbortComponent } from './core';
5
5
  import type { FetchType } from './filemanager';
6
6
 
@@ -28,20 +28,22 @@ export interface FileCommand<T extends ExternalAsset> extends FileData<T> {
28
28
  outputType?: string;
29
29
  }
30
30
 
31
- export interface IFileThread<T extends ExternalAsset = ExternalAsset> extends IAbortComponent, Required<FileData<T>> {
31
+ export interface IFileThread<T extends IHost = IHost, U extends ExternalAsset = ExternalAsset> extends IAbortComponent, Required<FileData<U>> {
32
32
  threadCount: number;
33
33
  readonly startTime: number;
34
34
  openThread(instance: IModule, timeout?: number): boolean;
35
35
  closeThread(instance: IModule, callback?: FunctionType<void>): boolean;
36
- getObject<U extends FileCommand<T>>(data?: PlainObject): U;
37
- get host(): IFileManager<T>;
36
+ getObject<V extends FileCommand<U>>(data?: PlainObject): V;
37
+ get host(): T;
38
38
  get queuedTasks(): FunctionType<void>[];
39
39
  get localUri(): string | undefined;
40
+ set mimeType(value);
41
+ get mimeType(): string;
40
42
  }
41
43
 
42
- export interface FileThreadConstructor<T extends ExternalAsset = ExternalAsset> {
43
- readonly prototype: IFileThread<T>;
44
- new(host: IFileManager<T>, file: ExternalAsset, threadCount: number): IFileThread<T>;
44
+ export interface FileThreadConstructor<T extends IHost = IHost, U extends ExternalAsset = ExternalAsset> {
45
+ readonly prototype: IFileThread<T, U>;
46
+ new(host: T, file: U, threadCount: number): IFileThread<T, U>;
45
47
  }
46
48
 
47
49
  export interface OutputFinalize<T extends ExternalAsset> extends FileCommand<T> {
package/lib/cloud.d.ts CHANGED
@@ -61,6 +61,7 @@ export interface CloudStorageUpload<T = unknown, U = string, V = unknown, W = st
61
61
  tags?: Record<string, string> | false;
62
62
  options?: T;
63
63
  fileGroup?: UploadContent[];
64
+ descendantsGroup?: string[];
64
65
  localStorage?: boolean;
65
66
  endpoint?: string;
66
67
  all?: boolean;
package/lib/compress.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { CompressFormat as ICompressFormat, CompressLevel as ICompressLevel
3
3
  import type { LogBaseOptions, LogTime } from './logger';
4
4
  import type { ThrowsAction } from './module';
5
5
 
6
- import type { BrotliOptions, ZlibOptions } from 'node:zlib';
6
+ import type { BrotliOptions, ZlibOptions, ZstdOptions } from 'node:zlib';
7
7
 
8
8
  type ResultCallback<T = Buffer | Uint8Array | null> = (err: unknown, data?: T, ext?: string) => void;
9
9
  type ResultData = Buffer | Uint8Array | string | null;
@@ -20,6 +20,8 @@ export interface CompressLevel extends ICompressLevel, ReadableOptions, ZlibOpti
20
20
 
21
21
  export interface BrotliCompressLevel extends CompressLevel, BrotliOptions, MimeTypeAction {}
22
22
 
23
+ export interface ZstdCompressLevel extends Omit<CompressLevel, "dictionary">, ZstdOptions {}
24
+
23
25
  export interface ReadableOptions extends ThrowsAction {}
24
26
 
25
27
  export type BufferLike = Buffer | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly number[];
package/lib/core.d.ts CHANGED
@@ -21,14 +21,16 @@ export interface AddEventListenerOptions {
21
21
  signal?: AbortSignal;
22
22
  }
23
23
 
24
- export interface IClient<T extends IHost, U extends ClientModule, V extends FunctionType<any, any> = FunctionType> extends IModule<T>, IExternalConfig<U, U extends ClientModule<infer W> ? W : unknown>, IExternalFunction<V> {
24
+ export interface IClient<T extends IHost, U extends ClientModule, V extends FunctionReturn<any> = FunctionReturn> extends IModule<T>, IExternalConfig<U, U extends ClientModule<infer W> ? W : unknown>, IExternalFunction<V> {
25
25
  init(...args: unknown[]): this;
26
26
  getUserSettings<X>(): X | null;
27
+ extensionsOf<W extends FunctionReturn>(type?: string, cache?: boolean): W[];
27
28
  set cacheDir(value: string);
28
29
  get cacheDir(): string;
29
30
  }
30
31
 
31
32
  export interface ClientConstructor<T extends IHost = IHost, U extends ClientModule = ClientModule> extends ModuleConstructor {
33
+ signExtensionType<V extends FunctionReturn>(method: V, ...type: string[]): V;
32
34
  readonly prototype: IClient<T, U>;
33
35
  new(module?: U): IClient<T, U>;
34
36
  }
@@ -65,6 +67,7 @@ export interface ClientDbConstructor<T extends IHost = IHost, U extends ClientMo
65
67
  readonly TRANSACTION_TERMINATE: number;
66
68
  readonly TRANSACTION_ABORT: number;
67
69
  readonly TRANSACTION_FAIL: number;
70
+ readonly HASH_ALGORITHM: string | undefined;
68
71
  loadSettings(settings: Pick<Settings, "process" | "memory">, password?: string): boolean;
69
72
  getTimeout(value: number | string | TimeoutAction | undefined): number;
70
73
  convertTime(value: number | string): number;
@@ -324,4 +327,4 @@ export interface WorkerMessage<T = PlainObject, U = Buffer> {
324
327
  options?: T;
325
328
  }
326
329
 
327
- export type WorkerChannelResponse<T = unknown> = (result: T, ...args: unknown[]) => void;
330
+ export type WorkerChannelResponse<T = unknown> = (result: T, ...args: any[]) => void;