@zwa73/utils 1.0.285 → 1.0.286
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DataStore, type JObject } from '@zwa73/js-utils';
|
|
2
2
|
/**JSON文件存储实现 */
|
|
3
3
|
export declare class JsonStore<T extends JObject> implements DataStore<T> {
|
|
4
4
|
/**存储的数据 */
|
|
@@ -9,8 +9,7 @@ export declare class JsonStore<T extends JObject> implements DataStore<T> {
|
|
|
9
9
|
private _filepath;
|
|
10
10
|
/**是否检查数据变更 */
|
|
11
11
|
private _checkChange;
|
|
12
|
-
|
|
13
|
-
* 构造函数
|
|
12
|
+
/**构造函数
|
|
14
13
|
* @param opt 配置选项
|
|
15
14
|
*/
|
|
16
15
|
constructor(opt: {
|
|
@@ -33,3 +32,13 @@ export declare class JsonStore<T extends JObject> implements DataStore<T> {
|
|
|
33
32
|
*/
|
|
34
33
|
getUid(): string;
|
|
35
34
|
}
|
|
35
|
+
/**可解析的数据存储源 */
|
|
36
|
+
export type ParseableDataStore<T> = string | T | DataStore<T>;
|
|
37
|
+
/**常用的数据存储实现 */
|
|
38
|
+
export declare class UtilDataStore {
|
|
39
|
+
/**解析数据存储器源
|
|
40
|
+
* @param source 数据存储源
|
|
41
|
+
* @returns 数据存储对象
|
|
42
|
+
*/
|
|
43
|
+
static parseDataStore<T>(source: ParseableDataStore<T>): DataStore<T>;
|
|
44
|
+
}
|
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JsonStore = void 0;
|
|
6
|
+
exports.UtilDataStore = exports.JsonStore = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const js_utils_1 = require("@zwa73/js-utils");
|
|
8
9
|
const UtilFileTools_1 = require("../UtilFileTools");
|
|
9
10
|
const UtilFunctions_1 = require("../UtilFunctions");
|
|
10
11
|
const UtilLogger_1 = require("../UtilLogger");
|
|
@@ -18,8 +19,7 @@ class JsonStore {
|
|
|
18
19
|
_filepath;
|
|
19
20
|
/**是否检查数据变更 */
|
|
20
21
|
_checkChange;
|
|
21
|
-
|
|
22
|
-
* 构造函数
|
|
22
|
+
/**构造函数
|
|
23
23
|
* @param opt 配置选项
|
|
24
24
|
*/
|
|
25
25
|
constructor(opt) {
|
|
@@ -66,3 +66,19 @@ class JsonStore {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.JsonStore = JsonStore;
|
|
69
|
+
/**常用的数据存储实现 */
|
|
70
|
+
class UtilDataStore {
|
|
71
|
+
/**解析数据存储器源
|
|
72
|
+
* @param source 数据存储源
|
|
73
|
+
* @returns 数据存储对象
|
|
74
|
+
*/
|
|
75
|
+
static parseDataStore(source) {
|
|
76
|
+
if (typeof source == 'string')
|
|
77
|
+
return new JsonStore({ filepath: source });
|
|
78
|
+
if (typeof source == 'object' && source != null && 'save' in source &&
|
|
79
|
+
typeof source.save == 'function')
|
|
80
|
+
return source;
|
|
81
|
+
return new js_utils_1.ObjectStore({ data: source });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.UtilDataStore = UtilDataStore;
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { JsFunc } from "@zwa73/js-utils";
|
|
2
|
-
import type { LogLevel } from "./UtilInterfaces";
|
|
2
|
+
import type { AnyString, LogLevel } from "./UtilInterfaces";
|
|
3
3
|
declare const HashAlgorithmList: readonly ["RSA-MD5", "RSA-RIPEMD160", "RSA-SHA1", "RSA-SHA1-2", "RSA-SHA224", "RSA-SHA256", "RSA-SHA3-224", "RSA-SHA3-256", "RSA-SHA3-384", "RSA-SHA3-512", "RSA-SHA384", "RSA-SHA512", "RSA-SHA512/224", "RSA-SHA512/256", "RSA-SM3", "blake2b512", "blake2s256", "id-rsassa-pkcs1-v1_5-with-sha3-224", "id-rsassa-pkcs1-v1_5-with-sha3-256", "id-rsassa-pkcs1-v1_5-with-sha3-384", "id-rsassa-pkcs1-v1_5-with-sha3-512", "md5", "md5-sha1", "md5WithRSAEncryption", "ripemd", "ripemd160", "ripemd160WithRSA", "rmd160", "sha1", "sha1WithRSAEncryption", "sha224", "sha224WithRSAEncryption", "sha256", "sha256WithRSAEncryption", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "sha384", "sha384WithRSAEncryption", "sha512", "sha512-224", "sha512-224WithRSAEncryption", "sha512-256", "sha512-256WithRSAEncryption", "sha512WithRSAEncryption", "shake128", "shake256", "sm3", "sm3WithRSAEncryption", "ssl3-md5", "ssl3-sha1"];
|
|
4
4
|
export type HashAlgorithm = typeof HashAlgorithmList[number];
|
|
5
5
|
/**执行选项 */
|
|
6
6
|
type ExecOpt = Partial<{
|
|
7
7
|
outlvl: LogLevel | ((arg: string) => any);
|
|
8
8
|
errlvl: LogLevel | ((arg: string) => any);
|
|
9
|
-
/**node_modules文件夹目录, 用于设定环境变量
|
|
10
|
-
|
|
9
|
+
/**node_modules文件夹目录, 用于设定环境变量 默认无
|
|
10
|
+
* undefined 时自动向上级查找
|
|
11
|
+
* 为‘None’ 时不使用
|
|
12
|
+
*/
|
|
13
|
+
nodeModules: AnyString | 'None';
|
|
11
14
|
/**工作路径 */
|
|
12
15
|
cwd: string;
|
|
13
16
|
/**额外环境变量 */
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -80,9 +80,10 @@ class _UtilFunc {
|
|
|
80
80
|
// 创建一个新的环境变量对象,并将项目的 node_modules/.bin 目录添加到 PATH 环境变量中
|
|
81
81
|
const env = Object.assign(Object.create(process.env), opt?.env ?? {});
|
|
82
82
|
const penv = opt?.nodeModules
|
|
83
|
-
?
|
|
83
|
+
? opt.nodeModules == 'None' ? ''
|
|
84
|
+
: path_1.default.join(UtilFileTools_1.UtilFT.currosizePath(opt.nodeModules), '.bin')
|
|
84
85
|
: UtilFileTools_1.UtilFT.currosizePath(await exports.UtilFunc.memoize(UtilFileTools_1.UtilFT.findNodeModulesDir)(process.cwd(), '.bin') ?? '');
|
|
85
|
-
if (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv))) {
|
|
86
|
+
if (opt?.nodeModules != "None" && (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv)))) {
|
|
86
87
|
UtilLogger_1.SLogger.warn(`UtilFunc.exec 错误, 没有检测到 node_modules/.bin 环境 penv:${penv}`);
|
|
87
88
|
_UtilFunc.checkEnv = false;
|
|
88
89
|
}
|