@zwa73/utils 1.0.79 → 1.0.81
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/{test/test.js → backup/repeatPromise.test.ts} +0 -1
- package/compile.bat +2 -0
- package/dist/QuickFunction.d.ts +2 -15
- package/dist/QuickFunction.js +21 -19
- package/dist/UtilCodecs.js +1 -1
- package/dist/UtilCom.js +1 -1
- package/dist/UtilDecorators.d.ts +1 -1
- package/dist/UtilDecorators.js +4 -3
- package/dist/UtilFP.js +1 -1
- package/dist/UtilFileTools.js +1 -1
- package/dist/UtilFunctions.d.ts +65 -18
- package/dist/UtilFunctions.js +143 -31
- package/dist/UtilInterfaces.d.ts +25 -15
- package/dist/UtilSymbol.d.ts +31 -9
- package/dist/UtilSymbol.js +23 -8
- package/dist/test/repeatTest.js +1 -1
- package/dist/test/test.js +16 -16
- package/jest/UtilFunction/queueProc.test.ts +23 -0
- package/jest/UtilFunction/repeatPromise.test.ts +38 -0
- package/jest/jest.test.ts +46 -0
- package/jest.config.js +16 -0
- package/package.json +12 -5
- package/release.bat +3 -4
- package/{postinstall.js → scripts/postinstall.js} +2 -2
- package/src/QuickFunction.ts +47 -27
- package/src/UtilDecorators.ts +3 -1
- package/src/UtilFunctions.ts +185 -46
- package/src/UtilInterfaces.ts +55 -13
- package/src/UtilSymbol.ts +37 -10
- package/src/test/repeatTest.ts +2 -2
- package/test.bat +1 -1
- package/tsconfig.compile.json +4 -0
- package/tsconfig.json +3 -2
- package/watch.bat +1 -0
- package/test/test.bat +0 -2
- package/testAndCompile.bat +0 -4
- package/tsCompile.bat +0 -3
- package/tsCompileWatch.bat +0 -2
- /package/{test.js → backup/SLogger.test.ts} +0 -0
- /package/{req_test → backup/req_test}/cjsRmjs.bat +0 -0
- /package/{req_test → backup/req_test}/cjsRmjs.cjs +0 -0
- /package/{req_test → backup/req_test}/mjsRcjs.bat +0 -0
- /package/{req_test → backup/req_test}/mjsRcjs.mjs +0 -0
- /package/{req_test → backup/req_test}/req.cjs +0 -0
- /package/{req_test → backup/req_test}/req.mjs +0 -0
package/dist/UtilSymbol.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
exports.
|
|
6
|
-
/**失败 */
|
|
3
|
+
exports.NoneOut = exports.Timeout = exports.Terminated = exports.Completed = exports.None = exports.Failed = exports.Success = void 0;
|
|
4
|
+
/**成功 经过验证的结果 */
|
|
5
|
+
exports.Success = Symbol("Success");
|
|
6
|
+
/**失败 可重试的 */
|
|
7
7
|
exports.Failed = Symbol("Failed");
|
|
8
|
-
|
|
9
|
-
exports.Terminated = Symbol("Terminated");
|
|
10
|
-
/**不存在 */
|
|
8
|
+
/**不存在 无 */
|
|
11
9
|
exports.None = Symbol("None");
|
|
12
|
-
|
|
10
|
+
/**完成 未经验证/未超时的结果
|
|
11
|
+
* Success扩展
|
|
12
|
+
* 仅在Success同时出现时使用
|
|
13
|
+
*/
|
|
14
|
+
exports.Completed = Symbol("Completed");
|
|
15
|
+
/**终止 熔断运行
|
|
16
|
+
* Failed扩展
|
|
17
|
+
* 仅在Failed同时出现时使用
|
|
18
|
+
*/
|
|
19
|
+
exports.Terminated = Symbol("Terminated");
|
|
20
|
+
/**超时 超时类型的失败
|
|
21
|
+
* Failed扩展
|
|
22
|
+
* 仅在超时时使用
|
|
23
|
+
*/
|
|
13
24
|
exports.Timeout = Symbol("Timeout");
|
|
25
|
+
exports.NoneOut = {
|
|
26
|
+
status: exports.None,
|
|
27
|
+
result: exports.None,
|
|
28
|
+
};
|
package/dist/test/repeatTest.js
CHANGED
|
@@ -11,7 +11,7 @@ async function mockAsyncFunction() {
|
|
|
11
11
|
}
|
|
12
12
|
// 验证函数,只有当结果为 "Success" 时才认为成功
|
|
13
13
|
function mockVerifyFunction(result) {
|
|
14
|
-
return result === "Success" ? __1.
|
|
14
|
+
return result === "Success" ? __1.Success : __1.Failed;
|
|
15
15
|
}
|
|
16
16
|
// 测试 repeatPromise 函数
|
|
17
17
|
__1.UtilFunc.repeatPromise(mockAsyncFunction, mockVerifyFunction, 3, 10)
|
package/dist/test/test.js
CHANGED
|
@@ -33,25 +33,25 @@ om.monfunc1(); //?
|
|
|
33
33
|
om.m1num; //?
|
|
34
34
|
const BASE_MAX = { 攻击: 24, 生命: 54, 防御: 16, 暴击: 5, 暴击伤害: 5, 攻击加成: 3.8, 生命加成: 3.8, 防御加成: 3.8 };
|
|
35
35
|
const 精调前 = [
|
|
36
|
-
{ 攻击: 17, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 3.5, 攻击加成: 3.0, 生命加成: 0, 防御加成: 3.4 },
|
|
37
|
-
{ 攻击: 19, 生命: 0, 防御: 0, 暴击: 4.5, 暴击伤害: 4.5, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 },
|
|
38
|
-
{ 攻击: 21, 生命: 0, 防御: 10, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.8, 生命加成: 0, 防御加成: 3.0 },
|
|
39
|
-
{ 攻击: 17, 生命: 48, 防御: 14, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 },
|
|
40
|
-
{ 攻击: 23, 生命: 0, 防御: 0, 暴击: 5, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 },
|
|
41
|
-
{ 攻击: 17, 生命: 53, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 },
|
|
42
|
-
{ 攻击: 21, 生命: 0, 防御: 0, 暴击: 3.5, 暴击伤害: 0, 攻击加成: 3.0, 生命加成: 0, 防御加成: 0 },
|
|
43
|
-
{ 攻击: 17, 生命: 0, 防御: 3.8, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 },
|
|
36
|
+
{ 攻击: 17, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 3.5, 攻击加成: 3.0, 生命加成: 0, 防御加成: 3.4 }, // 霰弹 专用消焰器
|
|
37
|
+
{ 攻击: 19, 生命: 0, 防御: 0, 暴击: 4.5, 暴击伤害: 4.5, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 霰弹 专用消音器
|
|
38
|
+
{ 攻击: 21, 生命: 0, 防御: 10, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.8, 生命加成: 0, 防御加成: 3.0 }, // 机枪 重型制退器
|
|
39
|
+
{ 攻击: 17, 生命: 48, 防御: 14, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 }, // 冲锋 消焰器攻击头
|
|
40
|
+
{ 攻击: 23, 生命: 0, 防御: 0, 暴击: 5, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 狙击 异位打击 快拆战术手电
|
|
41
|
+
{ 攻击: 17, 生命: 53, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 霰弹 减伤支援 钢化铆钉
|
|
42
|
+
{ 攻击: 21, 生命: 0, 防御: 0, 暴击: 3.5, 暴击伤害: 0, 攻击加成: 3.0, 生命加成: 0, 防御加成: 0 }, // 冲锋 异位打击 内瞄式红点
|
|
43
|
+
{ 攻击: 17, 生命: 0, 防御: 3.8, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 镭射插件
|
|
44
44
|
{ 攻击: 19, 生命: 38, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 折叠脚架
|
|
45
45
|
];
|
|
46
46
|
const 精调后 = [
|
|
47
|
-
{ 攻击: 26, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 8.1, 攻击加成: 7.5, 生命加成: 0, 防御加成: 5.8 },
|
|
48
|
-
{ 攻击: 31, 生命: 0, 防御: 0, 暴击: 10.4, 暴击伤害: 10.4, 攻击加成: 7.5, 生命加成: 0, 防御加成: 0 },
|
|
49
|
-
{ 攻击: 49, 生命: 0, 防御: 17, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.6, 生命加成: 0, 防御加成: 6.9 },
|
|
50
|
-
{ 攻击: 46, 生命: 116, 防御: 27, 暴击: 0, 暴击伤害: 0, 攻击加成: 5.0, 生命加成: 0, 防御加成: 0 },
|
|
51
|
-
{ 攻击: 42, 生命: 0, 防御: 0, 暴击: 11.5, 暴击伤害: 0, 攻击加成: 6.8, 生命加成: 0, 防御加成: 0 },
|
|
52
|
-
{ 攻击: 34, 生命: 101, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.5, 生命加成: 0, 防御加成: 0 },
|
|
53
|
-
{ 攻击: 38, 生命: 0, 防御: 0, 暴击: 8.4, 暴击伤害: 0, 攻击加成: 4.8, 生命加成: 0, 防御加成: 0 },
|
|
54
|
-
{ 攻击: 43, 生命: 0, 防御: 8.0, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.3, 生命加成: 0, 防御加成: 0 },
|
|
47
|
+
{ 攻击: 26, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 8.1, 攻击加成: 7.5, 生命加成: 0, 防御加成: 5.8 }, // 霰弹 专用消焰器
|
|
48
|
+
{ 攻击: 31, 生命: 0, 防御: 0, 暴击: 10.4, 暴击伤害: 10.4, 攻击加成: 7.5, 生命加成: 0, 防御加成: 0 }, // 霰弹 专用消音器
|
|
49
|
+
{ 攻击: 49, 生命: 0, 防御: 17, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.6, 生命加成: 0, 防御加成: 6.9 }, // 机枪 重型制退器
|
|
50
|
+
{ 攻击: 46, 生命: 116, 防御: 27, 暴击: 0, 暴击伤害: 0, 攻击加成: 5.0, 生命加成: 0, 防御加成: 0 }, // 冲锋 消焰器攻击头
|
|
51
|
+
{ 攻击: 42, 生命: 0, 防御: 0, 暴击: 11.5, 暴击伤害: 0, 攻击加成: 6.8, 生命加成: 0, 防御加成: 0 }, // 狙击 异位打击 快拆战术
|
|
52
|
+
{ 攻击: 34, 生命: 101, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.5, 生命加成: 0, 防御加成: 0 }, // 霰弹 减伤支援 钢化铆钉
|
|
53
|
+
{ 攻击: 38, 生命: 0, 防御: 0, 暴击: 8.4, 暴击伤害: 0, 攻击加成: 4.8, 生命加成: 0, 防御加成: 0 }, // 冲锋 异位打击 内瞄式红
|
|
54
|
+
{ 攻击: 43, 生命: 0, 防御: 8.0, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.3, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 镭射插件
|
|
55
55
|
{ 攻击: 42, 生命: 54, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.2, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 折叠脚架
|
|
56
56
|
];
|
|
57
57
|
const Pointify = (ed) => UtilFunctions_1.UtilFunc.mapEntries(ed, (k, v) => v ? v / BASE_MAX[k] : 0);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { UtilFunc } from '@';
|
|
2
|
+
import { test, expect } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
test('queueProc function', async () => {
|
|
5
|
+
const results:number[] = [];
|
|
6
|
+
const expectedResults:number[] = [];
|
|
7
|
+
const tasks = Array.from({length: 10}, (_, i) => {
|
|
8
|
+
const result = Math.floor(Math.random() * 100); // 随机生成结果
|
|
9
|
+
expectedResults.push(result);
|
|
10
|
+
return async () => {
|
|
11
|
+
await UtilFunc.sleep(Math.random() * 800); // 随机延迟
|
|
12
|
+
results.push(result);
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
console.log("结果应该为:",expectedResults);
|
|
16
|
+
|
|
17
|
+
// 同时启动所有任务,但由于 queueProc 的设计,它们应该按顺序完成
|
|
18
|
+
const promises = tasks.map(task => UtilFunc.queueProc('test', task));
|
|
19
|
+
await Promise.all(promises);
|
|
20
|
+
|
|
21
|
+
// 检查结果是否按顺序
|
|
22
|
+
expect(results).toEqual(expectedResults);
|
|
23
|
+
},10000);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Completed, Failed, PromiseStat, PromiseVerifyFn, Success, UtilFunc } from "@";
|
|
2
|
+
import { test, expect } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const timeList = [8000,1000,1000000] as const;
|
|
8
|
+
const resList = [Success,Failed,Failed] as const;
|
|
9
|
+
let index = 0;
|
|
10
|
+
|
|
11
|
+
// 模拟的异步函数,有一定几率失败
|
|
12
|
+
async function mockAsyncFunction() {
|
|
13
|
+
return new Promise<Success|Failed>((resolve, reject) => {
|
|
14
|
+
let delay = timeList[index];
|
|
15
|
+
let result = resList[index];
|
|
16
|
+
console.log('当前预期 延迟:',delay,' 结果:',result);
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
resolve(result);
|
|
19
|
+
}, delay);
|
|
20
|
+
index++;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 验证函数,只有当结果为 "Success" 时才认为成功
|
|
25
|
+
function mockVerifyFunction(result:Success|Failed):PromiseStat {
|
|
26
|
+
return result === Success ? Success : Failed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 测试 repeatPromise 函数
|
|
30
|
+
test('repeatPromise', async () => {
|
|
31
|
+
const repeatCount = 3;
|
|
32
|
+
const awaitTime = 5;
|
|
33
|
+
console.log("重试次数:",repeatCount," 超时时间:",awaitTime)
|
|
34
|
+
const result = await UtilFunc.repeatPromise(
|
|
35
|
+
mockAsyncFunction, mockVerifyFunction,
|
|
36
|
+
repeatCount, awaitTime);
|
|
37
|
+
expect(result).toBe(Success);
|
|
38
|
+
},10000);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { test, expect } from '@jest/globals';
|
|
2
|
+
// main.test.ts
|
|
3
|
+
const add = (a: number, b: number): number => a + b;
|
|
4
|
+
|
|
5
|
+
test('1+2等于3', () => {
|
|
6
|
+
expect(add(1, 2)).toBe(3);
|
|
7
|
+
});
|
|
8
|
+
test('console.log test', () => {
|
|
9
|
+
const consoleSpy = jest.spyOn(console, 'log');
|
|
10
|
+
|
|
11
|
+
// 这里是你的函数,它会打印 "成功" 或 "失败"
|
|
12
|
+
function yourFunction() {
|
|
13
|
+
console.log('成功');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
yourFunction();
|
|
17
|
+
|
|
18
|
+
expect(consoleSpy).toHaveBeenCalledWith('成功');
|
|
19
|
+
|
|
20
|
+
// 清理 spy
|
|
21
|
+
consoleSpy.mockRestore();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('mult console.log test', () => {
|
|
25
|
+
const consoleSpy = jest.spyOn(console, 'log');
|
|
26
|
+
|
|
27
|
+
// 这里是你的函数
|
|
28
|
+
function yourFunction() {
|
|
29
|
+
console.log("xxxx1234");
|
|
30
|
+
console.log("111abc22");
|
|
31
|
+
console.log("11def");
|
|
32
|
+
console.log("xxxxxxx");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
yourFunction();
|
|
36
|
+
|
|
37
|
+
// 检查 console.log 的输出中是否包含 "abc" 和 "def"
|
|
38
|
+
const hasAbc = consoleSpy.mock.calls.some(args => args.some(arg => arg.includes('abc')));
|
|
39
|
+
const hasDef = consoleSpy.mock.calls.some(args => args.some(arg => arg.includes('def')));
|
|
40
|
+
|
|
41
|
+
expect(hasAbc).toBe(true);
|
|
42
|
+
expect(hasDef).toBe(true);
|
|
43
|
+
|
|
44
|
+
// 清理 spy
|
|
45
|
+
consoleSpy.mockRestore();
|
|
46
|
+
});
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
roots: ['./jest'],
|
|
7
|
+
transform: {
|
|
8
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
9
|
+
},
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
'^@src/(.*)$': '<rootDir>/dist/$1',
|
|
12
|
+
'^@/(.*)$': '<rootDir>/$1',
|
|
13
|
+
'^@$': '<rootDir>/index'
|
|
14
|
+
},
|
|
15
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.81",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"postinstall": "start node postinstall.js",
|
|
9
|
-
"release": "call release.bat"
|
|
7
|
+
"test": "call npm run compile && jest",
|
|
8
|
+
"postinstall": "start node ./scripts/postinstall.js",
|
|
9
|
+
"release": "call release.bat",
|
|
10
|
+
"compile": "call tsc -p tsconfig.compile.json && call tsc-alias -p tsconfig.compile.json",
|
|
11
|
+
"watch": "start tsc-alias -w -p tsconfig.compile.json && start tsc -w -p tsconfig.compile.json"
|
|
10
12
|
},
|
|
11
13
|
"keywords": [
|
|
12
14
|
"zwa73"
|
|
@@ -28,6 +30,11 @@
|
|
|
28
30
|
"winston-daily-rotate-file": "^4.7.1"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"@types/
|
|
33
|
+
"@types/jest": "^29.5.12",
|
|
34
|
+
"@types/node": "^18.16.3",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"ts-jest": "^29.1.2",
|
|
37
|
+
"tsc-alias": "^1.8.8",
|
|
38
|
+
"typescript": "^5.3.3"
|
|
32
39
|
}
|
|
33
40
|
}
|
package/release.bat
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const currentVersion = require('
|
|
1
|
+
const currentVersion = require('../package.json').version;
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const { UtilFT } = require("
|
|
3
|
+
const { UtilFT } = require("../index");
|
|
4
4
|
const readline = require('readline');
|
|
5
5
|
|
|
6
6
|
// 将版本号转换为可以比较的数字
|
package/src/QuickFunction.ts
CHANGED
|
@@ -1,36 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UtilFunc } from "./UtilFunctions";
|
|
2
|
+
import { Outcome } from "./UtilInterfaces";
|
|
3
|
+
import { Completed, Failed, FailedLike, None, NoneOut, StatusSymbol, Success, SuccessLike, Terminated, Timeout } from "./UtilSymbol";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export const {
|
|
6
|
+
outcome,
|
|
7
|
+
matchProc,
|
|
8
|
+
sucesProc,
|
|
9
|
+
isFailed,
|
|
10
|
+
isSafeNumber,
|
|
11
|
+
isSuccess,
|
|
12
|
+
assertType,
|
|
13
|
+
assertLiteral,
|
|
14
|
+
deepClone,
|
|
15
|
+
sleep,
|
|
16
|
+
stringifyJToken,
|
|
17
|
+
getTime,
|
|
18
|
+
mapEntries,
|
|
19
|
+
composeMixinable
|
|
20
|
+
} = UtilFunc;
|
|
7
21
|
|
|
8
|
-
/**处理联合 简单值
|
|
9
|
-
* @param t - 目标值
|
|
10
|
-
* @param procObj - 所有可能的id组成的处理函数映射
|
|
11
|
-
* @returns 任意处理函数的返回值
|
|
12
|
-
*/
|
|
13
|
-
export function match<
|
|
14
|
-
T extends Keyable | Outcome<Keyable, unknown>,
|
|
15
|
-
P extends (T extends Keyable
|
|
16
|
-
? {[K in T]:(k:K)=>unknown}
|
|
17
|
-
: T extends Outcome<Keyable,unknown>
|
|
18
|
-
? {[K in T['status']]:(k:K,v:ExtractOutcome<T,K>['result'])=>unknown}
|
|
19
|
-
: never)>
|
|
20
|
-
(t:T, procObj:P):
|
|
21
|
-
P extends Record<any,(...args:any)=>any>
|
|
22
|
-
? {[K in keyof P]: ReturnType<P[K]>}[keyof P]
|
|
23
|
-
: never {
|
|
24
|
-
if (typeof t === 'string' || typeof t === 'number' || typeof t === 'symbol')
|
|
25
|
-
return (procObj as any)[t](t);
|
|
26
|
-
else
|
|
27
|
-
return (procObj as any)[t.status](t.status,t.result);
|
|
28
|
-
}
|
|
29
22
|
if(false){
|
|
23
|
+
let aaser = assertLiteral({a:1})
|
|
24
|
+
|
|
30
25
|
let a:"asd"|"dsa" = null as any;
|
|
31
|
-
const r =
|
|
26
|
+
const r = matchProc(a,{
|
|
32
27
|
"asd":(a)=>"ssa" as const,
|
|
33
28
|
"dsa":(b)=>"ssb" as const,
|
|
34
29
|
})
|
|
30
|
+
let b:Outcome<"a","123">|NoneOut = null as any;
|
|
31
|
+
const r1 = matchProc(b,{
|
|
32
|
+
"a":(a,s)=>"ssa" as const,
|
|
33
|
+
[None]:(b,s)=>"ssb" as const,
|
|
34
|
+
})
|
|
35
|
+
let udt = outcome("ssa","None");
|
|
36
|
+
|
|
37
|
+
type test = Outcome<"a"|"b",any> extends Outcome<"a",12>|Outcome<"b",34>
|
|
38
|
+
? "suc" : "fal"
|
|
39
|
+
let assa = isFailed(null as any as Failed)
|
|
40
|
+
let assb = isFailed(null as any as Failed|Success)
|
|
41
|
+
let assc = isFailed(null as any as Success)
|
|
42
|
+
let asssc = isFailed(null)
|
|
43
|
+
let assa1 = isFailed(null as any as Outcome<Failed,unknown>)
|
|
44
|
+
let assb1 = isFailed(null as any as Outcome<Failed|Success,unknown>)
|
|
45
|
+
let assc1 = isFailed(null as any as Outcome<Success,unknown>)
|
|
46
|
+
|
|
47
|
+
let proct = sucesProc(null as any as Outcome<Failed|Success,"123">|Outcome<Failed,"1234">|Outcome<Success,"1s23">,
|
|
48
|
+
(s)=>"ssa" as const,
|
|
49
|
+
(f)=>"ssad" as const,
|
|
50
|
+
()=>123 as const)
|
|
51
|
+
|
|
52
|
+
let matt = matchProc(null as any as Outcome<symbol,123>,{
|
|
53
|
+
|
|
54
|
+
})
|
|
35
55
|
}
|
|
36
56
|
|
package/src/UtilDecorators.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UtilFunc } from "./UtilFunctions";
|
|
2
|
+
import { UnwrapPromise } from "./UtilInterfaces";
|
|
2
3
|
import { SLogger } from "./UtilLogger";
|
|
3
4
|
|
|
4
5
|
type TDTg<T> =
|
|
@@ -136,7 +137,7 @@ export function DeferAsync<T extends (...args:any)=>Promise<any>>
|
|
|
136
137
|
};
|
|
137
138
|
}
|
|
138
139
|
/**try-catch包装 */
|
|
139
|
-
export function
|
|
140
|
+
export function Catch<T extends (...args:any)=>any>
|
|
140
141
|
(catchLogic:(error: any, ...args:Parameters<T>)=>ReturnType<T>):TDTg<T> {
|
|
141
142
|
return function(target, propertyKey, descriptor) {
|
|
142
143
|
const originalMethod = descriptor.value!;
|
|
@@ -198,6 +199,7 @@ class Example {
|
|
|
198
199
|
}
|
|
199
200
|
@LogCall()
|
|
200
201
|
@Defer((a,b)=>null)
|
|
202
|
+
@CatchAsync(async (a,b)=>123)
|
|
201
203
|
static async myMethod1(num: number,ss:string) {
|
|
202
204
|
return 312;
|
|
203
205
|
}
|