@wailsio/runtime 3.0.0-alpha.65 → 3.0.0-alpha.69
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/{src → dist}/application.js +2 -16
- package/dist/browser.js +20 -0
- package/dist/callable.js +144 -0
- package/dist/calls.js +194 -0
- package/dist/cancellable.js +792 -0
- package/dist/clipboard.js +30 -0
- package/dist/contextmenu.js +80 -0
- package/{src → dist}/create.js +2 -33
- package/dist/dialogs.js +134 -0
- package/dist/drag.js +222 -0
- package/dist/event_types.js +232 -0
- package/dist/events.js +114 -0
- package/dist/flags.js +23 -0
- package/dist/index.js +38 -0
- package/dist/listener.js +44 -0
- package/{src → dist}/nanoid.js +7 -11
- package/dist/runtime.js +63 -0
- package/dist/screens.js +38 -0
- package/dist/system.js +146 -0
- package/{src → dist}/utils.js +29 -20
- package/dist/window.js +570 -0
- package/{src → dist}/wml.js +52 -123
- package/package.json +43 -19
- package/types/application.d.ts +3 -10
- package/types/browser.d.ts +4 -4
- package/types/callable.d.ts +3 -0
- package/types/calls.d.ts +43 -49
- package/types/cancellable.d.ts +434 -0
- package/types/clipboard.d.ts +6 -5
- package/types/contextmenu.d.ts +1 -0
- package/types/create.d.ts +6 -27
- package/types/dialogs.d.ts +99 -143
- package/types/drag.d.ts +1 -0
- package/types/event_types.d.ts +221 -219
- package/types/events.d.ts +46 -250
- package/types/flags.d.ts +3 -3
- package/types/index.d.ts +16 -14
- package/types/listener.d.ts +9 -0
- package/types/nanoid.d.ts +1 -1
- package/types/runtime.d.ts +18 -26
- package/types/screens.d.ts +42 -76
- package/types/system.d.ts +59 -79
- package/types/utils.d.ts +15 -8
- package/types/window.d.ts +123 -224
- package/types/wml.d.ts +2 -6
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -22
- package/docs/assets/icons.js +0 -15
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -59
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1415
- package/docs/classes/Call.RuntimeError.html +0 -11
- package/docs/classes/Events.WailsEvent.html +0 -4
- package/docs/functions/Application.Hide.html +0 -2
- package/docs/functions/Application.Quit.html +0 -2
- package/docs/functions/Application.Show.html +0 -2
- package/docs/functions/Browser.OpenURL.html +0 -3
- package/docs/functions/Call.ByID.html +0 -8
- package/docs/functions/Call.ByName.html +0 -6
- package/docs/functions/Call.Call.html +0 -11
- package/docs/functions/Clipboard.SetText.html +0 -6
- package/docs/functions/Clipboard.Text.html +0 -3
- package/docs/functions/Create.Any.html +0 -2
- package/docs/functions/Create.Array.html +0 -4
- package/docs/functions/Create.ByteSlice.html +0 -3
- package/docs/functions/Create.Map.html +0 -4
- package/docs/functions/Create.Nullable.html +0 -3
- package/docs/functions/Create.Struct.html +0 -3
- package/docs/functions/Dialogs.Error.html +0 -5
- package/docs/functions/Dialogs.Info.html +0 -5
- package/docs/functions/Dialogs.OpenFile.html +0 -3
- package/docs/functions/Dialogs.Question.html +0 -5
- package/docs/functions/Dialogs.SaveFile.html +0 -3
- package/docs/functions/Dialogs.Warning.html +0 -5
- package/docs/functions/Events.Emit.html +0 -6
- package/docs/functions/Events.Off.html +0 -4
- package/docs/functions/Events.OffAll.html +0 -3
- package/docs/functions/Events.On.html +0 -7
- package/docs/functions/Events.OnMultiple.html +0 -8
- package/docs/functions/Events.Once.html +0 -7
- package/docs/functions/Events.setup.html +0 -1
- package/docs/functions/Flags.GetFlag.html +0 -6
- package/docs/functions/Screens.GetAll.html +0 -3
- package/docs/functions/Screens.GetCurrent.html +0 -3
- package/docs/functions/Screens.GetPrimary.html +0 -3
- package/docs/functions/System.Capabilities.html +0 -4
- package/docs/functions/System.Environment.html +0 -5
- package/docs/functions/System.IsAMD64.html +0 -3
- package/docs/functions/System.IsARM.html +0 -3
- package/docs/functions/System.IsARM64.html +0 -5
- package/docs/functions/System.IsDarkMode.html +0 -5
- package/docs/functions/System.IsDebug.html +0 -1
- package/docs/functions/System.IsLinux.html +0 -3
- package/docs/functions/System.IsMac.html +0 -3
- package/docs/functions/System.IsWindows.html +0 -3
- package/docs/functions/System.invoke.html +0 -1
- package/docs/functions/WML.Enable.html +0 -2
- package/docs/functions/WML.Reload.html +0 -2
- package/docs/functions/init.html +0 -1
- package/docs/index.html +0 -5
- package/docs/interfaces/Call.CallOptions.html +0 -7
- package/docs/interfaces/Dialogs.Button.html +0 -7
- package/docs/interfaces/Dialogs.FileFilter.html +0 -5
- package/docs/interfaces/Dialogs.MessageDialogOptions.html +0 -9
- package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +0 -33
- package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +0 -35
- package/docs/interfaces/Screens.Rect.html +0 -9
- package/docs/interfaces/Screens.Screen.html +0 -25
- package/docs/interfaces/Screens.Size.html +0 -5
- package/docs/interfaces/System.EnvironmentInfo.html +0 -11
- package/docs/interfaces/System.OSInfo.html +0 -9
- package/docs/modules/Application.html +0 -4
- package/docs/modules/Browser.html +0 -2
- package/docs/modules/Call.html +0 -6
- package/docs/modules/Clipboard.html +0 -3
- package/docs/modules/Create.html +0 -7
- package/docs/modules/Dialogs.html +0 -12
- package/docs/modules/Events.html +0 -10
- package/docs/modules/Flags.html +0 -2
- package/docs/modules/Screens.html +0 -7
- package/docs/modules/System.html +0 -14
- package/docs/modules/WML.html +0 -3
- package/docs/modules.html +0 -14
- package/docs/variables/Events.Types.html +0 -1
- package/docs/variables/Window.html +0 -2
- package/src/browser.js +0 -24
- package/src/calls.js +0 -221
- package/src/clipboard.js +0 -35
- package/src/contextmenu.js +0 -97
- package/src/dialogs.js +0 -200
- package/src/drag.js +0 -119
- package/src/event_types.js +0 -219
- package/src/events.js +0 -140
- package/src/flags.js +0 -25
- package/src/index.js +0 -60
- package/src/runtime.js +0 -92
- package/src/screens.js +0 -71
- package/src/system.js +0 -143
- package/src/window.js +0 -638
- package/tsconfig.json +0 -20
|
@@ -7,39 +7,25 @@
|
|
|
7
7
|
The electron alternative for Go
|
|
8
8
|
(c) Lea Anthony 2019-present
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { newRuntimeCallerWithID, objectNames } from "./runtime";
|
|
14
|
-
const call = newRuntimeCallerWithID(objectNames.Application, '');
|
|
15
|
-
|
|
10
|
+
import { newRuntimeCaller, objectNames } from "./runtime.js";
|
|
11
|
+
const call = newRuntimeCaller(objectNames.Application);
|
|
16
12
|
const HideMethod = 0;
|
|
17
13
|
const ShowMethod = 1;
|
|
18
14
|
const QuitMethod = 2;
|
|
19
|
-
|
|
20
15
|
/**
|
|
21
16
|
* Hides a certain method by calling the HideMethod function.
|
|
22
|
-
*
|
|
23
|
-
* @return {Promise<void>}
|
|
24
|
-
*
|
|
25
17
|
*/
|
|
26
18
|
export function Hide() {
|
|
27
19
|
return call(HideMethod);
|
|
28
20
|
}
|
|
29
|
-
|
|
30
21
|
/**
|
|
31
22
|
* Calls the ShowMethod and returns the result.
|
|
32
|
-
*
|
|
33
|
-
* @return {Promise<void>}
|
|
34
23
|
*/
|
|
35
24
|
export function Show() {
|
|
36
25
|
return call(ShowMethod);
|
|
37
26
|
}
|
|
38
|
-
|
|
39
27
|
/**
|
|
40
28
|
* Calls the QuitMethod to terminate the program.
|
|
41
|
-
*
|
|
42
|
-
* @return {Promise<void>}
|
|
43
29
|
*/
|
|
44
30
|
export function Quit() {
|
|
45
31
|
return call(QuitMethod);
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
import { newRuntimeCaller, objectNames } from "./runtime.js";
|
|
11
|
+
const call = newRuntimeCaller(objectNames.Browser);
|
|
12
|
+
const BrowserOpenURL = 0;
|
|
13
|
+
/**
|
|
14
|
+
* Open a browser window to the given URL.
|
|
15
|
+
*
|
|
16
|
+
* @param url - The URL to open
|
|
17
|
+
*/
|
|
18
|
+
export function OpenURL(url) {
|
|
19
|
+
return call(BrowserOpenURL, { url: url.toString() });
|
|
20
|
+
}
|
package/dist/callable.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Source: https://github.com/inspect-js/is-callable
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2015 Jordan Harband
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
var fnToStr = Function.prototype.toString;
|
|
24
|
+
var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply;
|
|
25
|
+
var badArrayLike;
|
|
26
|
+
var isCallableMarker;
|
|
27
|
+
if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') {
|
|
28
|
+
try {
|
|
29
|
+
badArrayLike = Object.defineProperty({}, 'length', {
|
|
30
|
+
get: function () {
|
|
31
|
+
throw isCallableMarker;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
isCallableMarker = {};
|
|
35
|
+
// eslint-disable-next-line no-throw-literal
|
|
36
|
+
reflectApply(function () { throw 42; }, null, badArrayLike);
|
|
37
|
+
}
|
|
38
|
+
catch (_) {
|
|
39
|
+
if (_ !== isCallableMarker) {
|
|
40
|
+
reflectApply = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
reflectApply = null;
|
|
46
|
+
}
|
|
47
|
+
var constructorRegex = /^\s*class\b/;
|
|
48
|
+
var isES6ClassFn = function isES6ClassFunction(value) {
|
|
49
|
+
try {
|
|
50
|
+
var fnStr = fnToStr.call(value);
|
|
51
|
+
return constructorRegex.test(fnStr);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return false; // not a function
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var tryFunctionObject = function tryFunctionToStr(value) {
|
|
58
|
+
try {
|
|
59
|
+
if (isES6ClassFn(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
fnToStr.call(value);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var toStr = Object.prototype.toString;
|
|
70
|
+
var objectClass = '[object Object]';
|
|
71
|
+
var fnClass = '[object Function]';
|
|
72
|
+
var genClass = '[object GeneratorFunction]';
|
|
73
|
+
var ddaClass = '[object HTMLAllCollection]'; // IE 11
|
|
74
|
+
var ddaClass2 = '[object HTML document.all class]';
|
|
75
|
+
var ddaClass3 = '[object HTMLCollection]'; // IE 9-10
|
|
76
|
+
var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag`
|
|
77
|
+
var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing
|
|
78
|
+
var isDDA = function isDocumentDotAll() { return false; };
|
|
79
|
+
if (typeof document === 'object') {
|
|
80
|
+
// Firefox 3 canonicalizes DDA to undefined when it's not accessed directly
|
|
81
|
+
var all = document.all;
|
|
82
|
+
if (toStr.call(all) === toStr.call(document.all)) {
|
|
83
|
+
isDDA = function isDocumentDotAll(value) {
|
|
84
|
+
/* globals document: false */
|
|
85
|
+
// in IE 6-8, typeof document.all is "object" and it's truthy
|
|
86
|
+
if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) {
|
|
87
|
+
try {
|
|
88
|
+
var str = toStr.call(value);
|
|
89
|
+
return (str === ddaClass
|
|
90
|
+
|| str === ddaClass2
|
|
91
|
+
|| str === ddaClass3 // opera 12.16
|
|
92
|
+
|| str === objectClass // IE 6-8
|
|
93
|
+
) && value('') == null; // eslint-disable-line eqeqeq
|
|
94
|
+
}
|
|
95
|
+
catch (e) { /**/ }
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function isCallableRefApply(value) {
|
|
102
|
+
if (isDDA(value)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (!value) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (typeof value !== 'function' && typeof value !== 'object') {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
reflectApply(value, null, badArrayLike);
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
if (e !== isCallableMarker) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return !isES6ClassFn(value) && tryFunctionObject(value);
|
|
120
|
+
}
|
|
121
|
+
function isCallableNoRefApply(value) {
|
|
122
|
+
if (isDDA(value)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if (!value) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (typeof value !== 'function' && typeof value !== 'object') {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
if (hasToStringTag) {
|
|
132
|
+
return tryFunctionObject(value);
|
|
133
|
+
}
|
|
134
|
+
if (isES6ClassFn(value)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
var strClass = toStr.call(value);
|
|
138
|
+
if (strClass !== fnClass && strClass !== genClass && !(/^\[object HTML/).test(strClass)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return tryFunctionObject(value);
|
|
142
|
+
}
|
|
143
|
+
;
|
|
144
|
+
export default reflectApply ? isCallableRefApply : isCallableNoRefApply;
|
package/dist/calls.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
import { CancellablePromise } from "./cancellable.js";
|
|
11
|
+
import { newRuntimeCaller, objectNames } from "./runtime.js";
|
|
12
|
+
import { nanoid } from "./nanoid.js";
|
|
13
|
+
// Setup
|
|
14
|
+
window._wails = window._wails || {};
|
|
15
|
+
window._wails.callResultHandler = resultHandler;
|
|
16
|
+
window._wails.callErrorHandler = errorHandler;
|
|
17
|
+
const call = newRuntimeCaller(objectNames.Call);
|
|
18
|
+
const cancelCall = newRuntimeCaller(objectNames.CancelCall);
|
|
19
|
+
const callResponses = new Map();
|
|
20
|
+
const CallBinding = 0;
|
|
21
|
+
const CancelMethod = 0;
|
|
22
|
+
/**
|
|
23
|
+
* Exception class that will be thrown in case the bound method returns an error.
|
|
24
|
+
* The value of the {@link RuntimeError#name} property is "RuntimeError".
|
|
25
|
+
*/
|
|
26
|
+
export class RuntimeError extends Error {
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a new RuntimeError instance.
|
|
29
|
+
* @param message - The error message.
|
|
30
|
+
* @param options - Options to be forwarded to the Error constructor.
|
|
31
|
+
*/
|
|
32
|
+
constructor(message, options) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
this.name = "RuntimeError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Handles the result of a call request.
|
|
39
|
+
*
|
|
40
|
+
* @param id - The id of the request to handle the result for.
|
|
41
|
+
* @param data - The result data of the request.
|
|
42
|
+
* @param isJSON - Indicates whether the data is JSON or not.
|
|
43
|
+
*/
|
|
44
|
+
function resultHandler(id, data, isJSON) {
|
|
45
|
+
const resolvers = getAndDeleteResponse(id);
|
|
46
|
+
if (!resolvers) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!data) {
|
|
50
|
+
resolvers.resolve(undefined);
|
|
51
|
+
}
|
|
52
|
+
else if (!isJSON) {
|
|
53
|
+
resolvers.resolve(data);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
try {
|
|
57
|
+
resolvers.resolve(JSON.parse(data));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
resolvers.reject(new TypeError("could not parse result: " + err.message, { cause: err }));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Handles the error from a call request.
|
|
66
|
+
*
|
|
67
|
+
* @param id - The id of the promise handler.
|
|
68
|
+
* @param data - The error data to reject the promise handler with.
|
|
69
|
+
* @param isJSON - Indicates whether the data is JSON or not.
|
|
70
|
+
*/
|
|
71
|
+
function errorHandler(id, data, isJSON) {
|
|
72
|
+
const resolvers = getAndDeleteResponse(id);
|
|
73
|
+
if (!resolvers) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!isJSON) {
|
|
77
|
+
resolvers.reject(new Error(data));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
let error;
|
|
81
|
+
try {
|
|
82
|
+
error = JSON.parse(data);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
resolvers.reject(new TypeError("could not parse error: " + err.message, { cause: err }));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
let options = {};
|
|
89
|
+
if (error.cause) {
|
|
90
|
+
options.cause = error.cause;
|
|
91
|
+
}
|
|
92
|
+
let exception;
|
|
93
|
+
switch (error.kind) {
|
|
94
|
+
case "ReferenceError":
|
|
95
|
+
exception = new ReferenceError(error.message, options);
|
|
96
|
+
break;
|
|
97
|
+
case "TypeError":
|
|
98
|
+
exception = new TypeError(error.message, options);
|
|
99
|
+
break;
|
|
100
|
+
case "RuntimeError":
|
|
101
|
+
exception = new RuntimeError(error.message, options);
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
exception = new Error(error.message, options);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
resolvers.reject(exception);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Retrieves and removes the response associated with the given ID from the callResponses map.
|
|
112
|
+
*
|
|
113
|
+
* @param id - The ID of the response to be retrieved and removed.
|
|
114
|
+
* @returns The response object associated with the given ID, if any.
|
|
115
|
+
*/
|
|
116
|
+
function getAndDeleteResponse(id) {
|
|
117
|
+
const response = callResponses.get(id);
|
|
118
|
+
callResponses.delete(id);
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Generates a unique ID using the nanoid library.
|
|
123
|
+
*
|
|
124
|
+
* @returns A unique ID that does not exist in the callResponses set.
|
|
125
|
+
*/
|
|
126
|
+
function generateID() {
|
|
127
|
+
let result;
|
|
128
|
+
do {
|
|
129
|
+
result = nanoid();
|
|
130
|
+
} while (callResponses.has(result));
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Call a bound method according to the given call options.
|
|
135
|
+
*
|
|
136
|
+
* In case of failure, the returned promise will reject with an exception
|
|
137
|
+
* among ReferenceError (unknown method), TypeError (wrong argument count or type),
|
|
138
|
+
* {@link RuntimeError} (method returned an error), or other (network or internal errors).
|
|
139
|
+
* The exception might have a "cause" field with the value returned
|
|
140
|
+
* by the application- or service-level error marshaling functions.
|
|
141
|
+
*
|
|
142
|
+
* @param options - A method call descriptor.
|
|
143
|
+
* @returns The result of the call.
|
|
144
|
+
*/
|
|
145
|
+
export function Call(options) {
|
|
146
|
+
const id = generateID();
|
|
147
|
+
const result = CancellablePromise.withResolvers();
|
|
148
|
+
callResponses.set(id, { resolve: result.resolve, reject: result.reject });
|
|
149
|
+
const request = call(CallBinding, Object.assign({ "call-id": id }, options));
|
|
150
|
+
let running = false;
|
|
151
|
+
request.then(() => {
|
|
152
|
+
running = true;
|
|
153
|
+
}, (err) => {
|
|
154
|
+
callResponses.delete(id);
|
|
155
|
+
result.reject(err);
|
|
156
|
+
});
|
|
157
|
+
const cancel = () => {
|
|
158
|
+
callResponses.delete(id);
|
|
159
|
+
return cancelCall(CancelMethod, { "call-id": id }).catch((err) => {
|
|
160
|
+
console.error("Error while requesting binding call cancellation:", err);
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
result.oncancelled = () => {
|
|
164
|
+
if (running) {
|
|
165
|
+
return cancel();
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return request.then(cancel);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
return result.promise;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Calls a bound method by name with the specified arguments.
|
|
175
|
+
* See {@link Call} for details.
|
|
176
|
+
*
|
|
177
|
+
* @param methodName - The name of the method in the format 'package.struct.method'.
|
|
178
|
+
* @param args - The arguments to pass to the method.
|
|
179
|
+
* @returns The result of the method call.
|
|
180
|
+
*/
|
|
181
|
+
export function ByName(methodName, ...args) {
|
|
182
|
+
return Call({ methodName, args });
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Calls a method by its numeric ID with the specified arguments.
|
|
186
|
+
* See {@link Call} for details.
|
|
187
|
+
*
|
|
188
|
+
* @param methodID - The ID of the method to call.
|
|
189
|
+
* @param args - The arguments to pass to the method.
|
|
190
|
+
* @return The result of the method call.
|
|
191
|
+
*/
|
|
192
|
+
export function ByID(methodID, ...args) {
|
|
193
|
+
return Call({ methodID, args });
|
|
194
|
+
}
|