@wailsio/runtime 3.0.0-alpha.21 → 3.0.0-alpha.23
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/package.json +4 -1
- package/src/calls.js +3 -9
- package/src/create.js +125 -0
- package/src/index.js +2 -0
- package/types/create.d.ts +45 -0
- package/types/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wailsio/runtime",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.23",
|
|
4
4
|
"description": "Wails Runtime",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -27,5 +27,8 @@
|
|
|
27
27
|
"typedoc": "^0.25.7",
|
|
28
28
|
"typedoc-plugin-markdown": "^3.17.1",
|
|
29
29
|
"typescript": "^5.3.3"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"nanoid": "^5.0.7"
|
|
30
33
|
}
|
|
31
34
|
}
|
package/src/calls.js
CHANGED
|
@@ -113,7 +113,7 @@ function callBinding(type, options = {}) {
|
|
|
113
113
|
queuedCancel = true;
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
return p;
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -130,19 +130,13 @@ export function Call(options) {
|
|
|
130
130
|
/**
|
|
131
131
|
* Executes a method by name.
|
|
132
132
|
*
|
|
133
|
-
* @param {string}
|
|
133
|
+
* @param {string} methodName - The name of the method in the format 'package.struct.method'.
|
|
134
134
|
* @param {...*} args - The arguments to pass to the method.
|
|
135
135
|
* @throws {Error} If the name is not a string or is not in the correct format.
|
|
136
136
|
* @returns {*} The result of the method execution.
|
|
137
137
|
*/
|
|
138
|
-
export function ByName(
|
|
139
|
-
if (typeof name !== "string" || name.split(".").length !== 3) {
|
|
140
|
-
throw new Error("CallByName requires a string in the format 'package.struct.method'");
|
|
141
|
-
}
|
|
142
|
-
let [packageName, structName, methodName] = name.split(".");
|
|
138
|
+
export function ByName(methodName, ...args) {
|
|
143
139
|
return callBinding(CallBinding, {
|
|
144
|
-
packageName,
|
|
145
|
-
structName,
|
|
146
140
|
methodName,
|
|
147
141
|
args
|
|
148
142
|
});
|
package/src/create.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Any is a dummy creation function for simple or unknown types.
|
|
15
|
+
* @template T
|
|
16
|
+
* @param {any} source
|
|
17
|
+
* @returns {T}
|
|
18
|
+
*/
|
|
19
|
+
export function Any(source) {
|
|
20
|
+
return /** @type {T} */(source);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ByteSlice is a creation function that replaces
|
|
25
|
+
* null strings with empty strings.
|
|
26
|
+
* @param {any} source
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function ByteSlice(source) {
|
|
30
|
+
return /** @type {any} */((source == null) ? "" : source);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Array takes a creation function for an arbitrary type
|
|
35
|
+
* and returns an in-place creation function for an array
|
|
36
|
+
* whose elements are of that type.
|
|
37
|
+
* @template T
|
|
38
|
+
* @param {(any) => T} element
|
|
39
|
+
* @returns {(any) => T[]}
|
|
40
|
+
*/
|
|
41
|
+
export function Array(element) {
|
|
42
|
+
if (element === Any) {
|
|
43
|
+
return (source) => (source === null ? [] : source);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (source) => {
|
|
47
|
+
if (source === null) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < source.length; i++) {
|
|
51
|
+
source[i] = element(source[i]);
|
|
52
|
+
}
|
|
53
|
+
return source;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Map takes creation functions for two arbitrary types
|
|
59
|
+
* and returns an in-place creation function for an object
|
|
60
|
+
* whose keys and values are of those types.
|
|
61
|
+
* @template K, V
|
|
62
|
+
* @param {(any) => K} key
|
|
63
|
+
* @param {(any) => V} value
|
|
64
|
+
* @returns {(any) => { [_: K]: V }}
|
|
65
|
+
*/
|
|
66
|
+
export function Map(key, value) {
|
|
67
|
+
if (value === Any) {
|
|
68
|
+
return (source) => (source === null ? {} : source);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (source) => {
|
|
72
|
+
if (source === null) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
for (const key in source) {
|
|
76
|
+
source[key] = value(source[key]);
|
|
77
|
+
}
|
|
78
|
+
return source;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Nullable takes a creation function for an arbitrary type
|
|
84
|
+
* and returns a creation function for a nullable value of that type.
|
|
85
|
+
* @template T
|
|
86
|
+
* @param {(any) => T} element
|
|
87
|
+
* @returns {(any) => (T | null)}
|
|
88
|
+
*/
|
|
89
|
+
export function Nullable(element) {
|
|
90
|
+
if (element === Any) {
|
|
91
|
+
return Any;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (source) => (source === null ? null : element(source));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Struct takes an object mapping field names to creation functions
|
|
99
|
+
* and returns an in-place creation function for a struct.
|
|
100
|
+
* @template {{ [_: string]: ((any) => any) }} T
|
|
101
|
+
* @template {{ [Key in keyof T]?: ReturnType<T[Key]> }} U
|
|
102
|
+
* @param {T} createField
|
|
103
|
+
* @returns {(any) => U}
|
|
104
|
+
*/
|
|
105
|
+
export function Struct(createField) {
|
|
106
|
+
let allAny = true;
|
|
107
|
+
for (const name in createField) {
|
|
108
|
+
if (createField[name] !== Any) {
|
|
109
|
+
allAny = false;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (allAny) {
|
|
114
|
+
return Any;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (source) => {
|
|
118
|
+
for (const name in createField) {
|
|
119
|
+
if (name in source) {
|
|
120
|
+
source[name] = createField[name](source[name]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return source;
|
|
124
|
+
};
|
|
125
|
+
}
|
package/src/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import * as Application from "./application";
|
|
|
19
19
|
import * as Browser from "./browser";
|
|
20
20
|
import * as Call from "./calls";
|
|
21
21
|
import * as Clipboard from "./clipboard";
|
|
22
|
+
import * as Create from "./create";
|
|
22
23
|
import * as Dialogs from "./dialogs";
|
|
23
24
|
import * as Events from "./events";
|
|
24
25
|
import * as Flags from "./flags";
|
|
@@ -32,6 +33,7 @@ export {
|
|
|
32
33
|
Browser,
|
|
33
34
|
Call,
|
|
34
35
|
Clipboard,
|
|
36
|
+
Create,
|
|
35
37
|
Dialogs,
|
|
36
38
|
Events,
|
|
37
39
|
Flags,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Any is a dummy creation function for simple or unknown types.
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {any} source
|
|
5
|
+
* @returns {T}
|
|
6
|
+
*/
|
|
7
|
+
export function Any<T>(source: any): T;
|
|
8
|
+
/**
|
|
9
|
+
* Array takes a creation function for an arbitrary type
|
|
10
|
+
* and returns an in-place creation function for an array
|
|
11
|
+
* whose elements are of that type.
|
|
12
|
+
* @template T
|
|
13
|
+
* @param {(any) => T} element
|
|
14
|
+
* @returns {(any) => T[]}
|
|
15
|
+
*/
|
|
16
|
+
export function Array<T>(element: (any: any) => T): (any: any) => T[];
|
|
17
|
+
/**
|
|
18
|
+
* Map takes creation functions for two arbitrary types
|
|
19
|
+
* and returns an in-place creation function for an object
|
|
20
|
+
* whose keys and values are of those types.
|
|
21
|
+
* @template K, V
|
|
22
|
+
* @param {(any) => K} key
|
|
23
|
+
* @param {(any) => V} value
|
|
24
|
+
* @returns {(any) => { [_: K]: V }}
|
|
25
|
+
*/
|
|
26
|
+
export function Map<K, V>(key: (any: any) => K, value: (any: any) => V): (any: any) => {};
|
|
27
|
+
/**
|
|
28
|
+
* Nullable takes a creation function for an arbitrary type
|
|
29
|
+
* and returns a creation function for a nullable value of that type.
|
|
30
|
+
* @template T
|
|
31
|
+
* @param {(any) => T} element
|
|
32
|
+
* @returns {(any) => (T | null)}
|
|
33
|
+
*/
|
|
34
|
+
export function Nullable<T>(element: (any: any) => T): (any: any) => T;
|
|
35
|
+
/**
|
|
36
|
+
* Struct takes an object mapping field names to creation functions
|
|
37
|
+
* and returns an in-place creation function for a struct.
|
|
38
|
+
* @template {{ [_: string]: ((any) => any) }} T
|
|
39
|
+
* @template {{ [Key in keyof T]?: ReturnType<T[Key]> }} U
|
|
40
|
+
* @param {T} createField
|
|
41
|
+
* @returns {(any) => U}
|
|
42
|
+
*/
|
|
43
|
+
export function Struct<T extends {
|
|
44
|
+
[_: string]: (any: any) => any;
|
|
45
|
+
}, U extends { [Key in keyof T]?: ReturnType<T[Key]>; }>(createField: T): (any: any) => U;
|
package/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as Application from "./application";
|
|
|
2
2
|
import * as Browser from "./browser";
|
|
3
3
|
import * as Call from "./calls";
|
|
4
4
|
import * as Clipboard from "./clipboard";
|
|
5
|
+
import * as Create from "./create";
|
|
5
6
|
import * as Dialogs from "./dialogs";
|
|
6
7
|
import * as Events from "./events";
|
|
7
8
|
import * as Flags from "./flags";
|
|
@@ -9,4 +10,4 @@ import * as Screens from "./screens";
|
|
|
9
10
|
import * as System from "./system";
|
|
10
11
|
import Window from "./window";
|
|
11
12
|
import * as WML from "./wml";
|
|
12
|
-
export { Application, Browser, Call, Clipboard, Dialogs, Events, Flags, Screens, System, Window, WML };
|
|
13
|
+
export { Application, Browser, Call, Clipboard, Create, Dialogs, Events, Flags, Screens, System, Window, WML };
|