@zwa73/dev-utils 1.0.70 → 1.0.71
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.
@@ -2528,9 +2528,9 @@
|
|
2528
2528
|
}
|
2529
2529
|
},
|
2530
2530
|
"node_modules/@zwa73/utils": {
|
2531
|
-
"version": "1.0.
|
2532
|
-
"resolved": "https://registry.npmjs.org/@zwa73/utils/-/utils-1.0.
|
2533
|
-
"integrity": "sha512-
|
2531
|
+
"version": "1.0.155",
|
2532
|
+
"resolved": "https://registry.npmjs.org/@zwa73/utils/-/utils-1.0.155.tgz",
|
2533
|
+
"integrity": "sha512-n7Tb3oLA6cLi5VY2XsPmnfghPzG2iiV24twWLz4MY8Edkv13Qog/KdFVuJlNcXTlRHHyTIWb0aKeFAM5E3mDnQ==",
|
2534
2534
|
"hasInstallScript": true,
|
2535
2535
|
"dependencies": {
|
2536
2536
|
"@deepkit/type": "^1.0.1-alpha.153",
|
@@ -15611,9 +15611,9 @@
|
|
15611
15611
|
}
|
15612
15612
|
},
|
15613
15613
|
"@zwa73/utils": {
|
15614
|
-
"version": "1.0.
|
15615
|
-
"resolved": "https://registry.npmjs.org/@zwa73/utils/-/utils-1.0.
|
15616
|
-
"integrity": "sha512-
|
15614
|
+
"version": "1.0.155",
|
15615
|
+
"resolved": "https://registry.npmjs.org/@zwa73/utils/-/utils-1.0.155.tgz",
|
15616
|
+
"integrity": "sha512-n7Tb3oLA6cLi5VY2XsPmnfghPzG2iiV24twWLz4MY8Edkv13Qog/KdFVuJlNcXTlRHHyTIWb0aKeFAM5E3mDnQ==",
|
15617
15617
|
"requires": {
|
15618
15618
|
"@deepkit/type": "^1.0.1-alpha.153",
|
15619
15619
|
"fluent-ffmpeg": "2.1.2",
|
@@ -1,19 +1,34 @@
|
|
1
|
-
import {
|
1
|
+
import { AllExtends, JToken, UtilFT } from "@zwa73/utils";
|
2
2
|
import { IpcMainInvokeEvent, app } from "electron";
|
3
3
|
|
4
|
+
/**桥函数化 */
|
5
|
+
const bridgeify = <F extends (...args: any[]) => any>(func:F):
|
6
|
+
F extends (...args:infer IN)=>infer OUT
|
7
|
+
? AllExtends<IN,JToken> extends true
|
8
|
+
? OUT extends JToken|void|Promise<JToken|void>
|
9
|
+
? (e:IpcMainInvokeEvent,...args:Parameters<F>)=>ReturnType<F>
|
10
|
+
: Error&"返回值无法序列化"
|
11
|
+
: Error&"传入值无法序列化"
|
12
|
+
: never =>
|
13
|
+
((e:IpcMainInvokeEvent,...args:Parameters<F>):ReturnType<F>=>
|
14
|
+
(func as any)(...args)) as any;
|
15
|
+
|
4
16
|
/**后端桥对象 */
|
5
17
|
export const BridgeBackend = {
|
18
|
+
loadJsonFile :bridgeify(UtilFT.writeJSONFile),
|
19
|
+
writeJSONFile:bridgeify(UtilFT.writeJSONFile),
|
6
20
|
getAppPath() {
|
7
21
|
return app.getAppPath();
|
8
22
|
},
|
9
23
|
test(e: IpcMainInvokeEvent, text: string) {
|
10
|
-
return text +
|
24
|
+
return text + 0;
|
11
25
|
},
|
12
26
|
};
|
13
27
|
export type BridgeBackend = typeof BridgeBackend;
|
14
28
|
|
15
29
|
//断言确保桥符合类型
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
} & { getBridgeKeys?: never }>(
|
30
|
+
const assertBridge = <
|
31
|
+
T extends {
|
32
|
+
[key in string|number|symbol]: (arg1: IpcMainInvokeEvent, ...args: any[]) => any;
|
33
|
+
} & { getBridgeKeys?: never } >(t:T) => undefined;
|
34
|
+
assertBridge(BridgeBackend);
|
@@ -84,7 +84,7 @@ type RemoveIpcEventArg<T> =
|
|
84
84
|
/**前端桥对象定义 */
|
85
85
|
export type BridgeDefine = {
|
86
86
|
[P in keyof BridgeBackend]: BridgeBackend[P] extends (...args: infer Arg) => infer Out
|
87
|
-
? RemoveIpcEventArg<(...args: Arg) => Promise<Out>>
|
87
|
+
? RemoveIpcEventArg<(...args: Arg) => Out extends Promise<any> ? Out : Promise<Out>>
|
88
88
|
: never;
|
89
89
|
};
|
90
90
|
//#endregion
|
package/package.json
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.71",
|
4
4
|
"description": "编译与调试工具",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
7
7
|
"test": "jest",
|
8
8
|
"release": "powershell scripts/release",
|
9
9
|
"compile": "powershell scripts/compile",
|
10
|
-
"watch": "powershell scripts/watch"
|
11
|
-
"postinstall": "start node scripts/postinstall.js"
|
10
|
+
"watch": "powershell scripts/watch"
|
12
11
|
},
|
13
12
|
"keywords": [
|
14
13
|
"schema"
|