javonet-nodejs-sdk 2.5.17 → 2.5.18
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/dist/core/handler/AbstractHandler.cjs +23 -6
- package/dist/core/handler/ArrayGetItemHandler.cjs +4 -1
- package/dist/core/handler/ArrayGetRankHandler.cjs +3 -0
- package/dist/core/handler/ArrayGetSizeHandler.cjs +3 -0
- package/dist/core/handler/ArrayHandler.cjs +3 -0
- package/dist/core/handler/ArraySetItemHandler.cjs +4 -1
- package/dist/core/handler/CastingHandler.cjs +3 -1
- package/dist/core/handler/ConvertTypeHandler.cjs +4 -4
- package/dist/core/handler/CreateClassInstanceHandler.cjs +5 -2
- package/dist/core/handler/DestructReferenceHandler.cjs +3 -0
- package/dist/core/handler/EnableNamespaceHandler.cjs +3 -0
- package/dist/core/handler/EnableTypeHandler.cjs +3 -0
- package/dist/core/handler/GetGlobalStaticFieldHandler.cjs +3 -0
- package/dist/core/handler/GetInstanceFieldHandler.cjs +3 -0
- package/dist/core/handler/GetInstanceMethodAsDelegateHandler.cjs +15 -4
- package/dist/core/handler/GetStaticFieldHandler.cjs +4 -0
- package/dist/core/handler/GetStaticMethodAsDelegateHandler.cjs +8 -6
- package/dist/core/handler/GetTypeHandler.cjs +10 -2
- package/dist/core/handler/Handler.cjs +8 -11
- package/dist/core/handler/InvokeGlobalFunctionHandler.cjs +3 -0
- package/dist/core/handler/InvokeInstanceMethodHandler.cjs +3 -0
- package/dist/core/handler/InvokeStaticMethodHandler.cjs +3 -0
- package/dist/core/handler/LoadLibraryHandler.cjs +4 -0
- package/dist/core/handler/SetGlobalStaticFieldHandler.cjs +3 -0
- package/dist/core/handler/SetInstanceFieldHandler.cjs +3 -0
- package/dist/core/handler/SetStaticFieldHandler.cjs +3 -0
- package/dist/core/handler/ValueHandler.cjs +4 -0
- package/dist/core/interpreter/Interpreter.cjs +28 -12
- package/dist/core/namespaceCache/NamespaceCache.cjs +12 -0
- package/dist/core/protocol/CommandDeserializer.cjs +10 -2
- package/dist/core/protocol/CommandSerializer.cjs +24 -4
- package/dist/core/protocol/TypeDeserializer.cjs +35 -0
- package/dist/core/protocol/TypeSerializer.cjs +51 -7
- package/dist/core/receiver/Receiver.cjs +1 -1
- package/dist/core/receiver/ReceiverNative.cjs +6 -0
- package/dist/core/transmitter/Transmitter.cjs +18 -2
- package/dist/core/transmitter/TransmitterWebsocket.cjs +8 -5
- package/dist/core/transmitter/TransmitterWebsocketBrowser.cjs +1 -1
- package/dist/core/transmitter/TransmitterWrapper.cjs +25 -8
- package/dist/core/typeCache/TypeCache.cjs +8 -0
- package/dist/core/webSocketClient/WebSocketClient.cjs +22 -12
- package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +2 -2
- package/dist/sdk/ConfigRuntimeFactory.cjs +60 -55
- package/dist/sdk/InvocationContext.cjs +81 -23
- package/dist/sdk/Javonet.cjs +14 -33
- package/dist/sdk/RuntimeContext.cjs +85 -30
- package/dist/sdk/RuntimeFactory.cjs +3 -0
- package/dist/sdk/tools/ActivationHelper.cjs +66 -0
- package/dist/sdk/tools/JsonResolver.cjs +214 -0
- package/dist/types/core/handler/AbstractHandler.d.ts +23 -4
- package/dist/types/core/handler/ArrayGetItemHandler.d.ts +8 -1
- package/dist/types/core/handler/ArrayGetRankHandler.d.ts +8 -1
- package/dist/types/core/handler/ArrayGetSizeHandler.d.ts +8 -1
- package/dist/types/core/handler/ArrayHandler.d.ts +8 -1
- package/dist/types/core/handler/ArraySetItemHandler.d.ts +8 -1
- package/dist/types/core/handler/CastingHandler.d.ts +4 -0
- package/dist/types/core/handler/ConvertTypeHandler.d.ts +8 -4
- package/dist/types/core/handler/CreateClassInstanceHandler.d.ts +8 -1
- package/dist/types/core/handler/DestructReferenceHandler.d.ts +8 -1
- package/dist/types/core/handler/EnableNamespaceHandler.d.ts +8 -1
- package/dist/types/core/handler/EnableTypeHandler.d.ts +8 -1
- package/dist/types/core/handler/GetGlobalStaticFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/GetInstanceFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/GetStaticFieldHandler.d.ts +9 -1
- package/dist/types/core/handler/GetStaticMethodAsDelegateHandler.d.ts +4 -3
- package/dist/types/core/handler/GetTypeHandler.d.ts +17 -8
- package/dist/types/core/handler/Handler.d.ts +8 -8
- package/dist/types/core/handler/InvokeDelegateHandler.d.ts +4 -0
- package/dist/types/core/handler/InvokeGlobalFunctionHandler.d.ts +8 -1
- package/dist/types/core/handler/InvokeInstanceMethodHandler.d.ts +8 -1
- package/dist/types/core/handler/InvokeStaticMethodHandler.d.ts +8 -1
- package/dist/types/core/handler/LoadLibraryHandler.d.ts +8 -3
- package/dist/types/core/handler/SetGlobalStaticFieldHandler.d.ts +4 -0
- package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/SetStaticFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/ValueHandler.d.ts +9 -1
- package/dist/types/core/interpreter/Interpreter.d.ts +11 -10
- package/dist/types/core/namespaceCache/NamespaceCache.d.ts +17 -5
- package/dist/types/core/protocol/CommandDeserializer.d.ts +10 -3
- package/dist/types/core/protocol/CommandSerializer.d.ts +19 -2
- package/dist/types/core/protocol/TypeDeserializer.d.ts +46 -11
- package/dist/types/core/protocol/TypeSerializer.d.ts +53 -13
- package/dist/types/core/receiver/Receiver.d.ts +2 -2
- package/dist/types/core/receiver/ReceiverNative.d.ts +8 -2
- package/dist/types/core/transmitter/Transmitter.d.ts +20 -4
- package/dist/types/core/transmitter/TransmitterWebsocket.d.ts +8 -4
- package/dist/types/core/transmitter/TransmitterWebsocketBrowser.d.ts +4 -7
- package/dist/types/core/transmitter/TransmitterWrapper.d.ts +12 -3
- package/dist/types/core/typeCache/TypeCache.d.ts +15 -5
- package/dist/types/core/webSocketClient/WebSocketClient.d.ts +17 -21
- package/dist/types/sdk/ConfigRuntimeFactory.d.ts +9 -6
- package/dist/types/sdk/InvocationContext.d.ts +38 -6
- package/dist/types/sdk/Javonet.d.ts +12 -7
- package/dist/types/sdk/RuntimeContext.d.ts +23 -7
- package/dist/types/sdk/RuntimeFactory.d.ts +9 -2
- package/dist/types/sdk/tools/ActivationHelper.d.ts +20 -0
- package/dist/types/sdk/tools/JsonResolver.d.ts +87 -0
- package/dist/types/utils/Command.d.ts +18 -14
- package/dist/types/utils/CustomError.d.ts +5 -1
- package/dist/types/utils/Runtime.d.ts +1 -2
- package/dist/types/utils/RuntimeNameHandler.d.ts +6 -2
- package/dist/types/utils/Type.d.ts +1 -0
- package/dist/types/utils/TypesHandler.d.ts +16 -0
- package/dist/types/utils/UtilsConst.d.ts +32 -0
- package/dist/types/utils/connectionData/IConnectionData.d.ts +16 -3
- package/dist/types/utils/connectionData/InMemoryConnectionData.d.ts +4 -3
- package/dist/types/utils/connectionData/WsConnectionData.d.ts +7 -10
- package/dist/types/utils/nodejs/connectionData/TcpConnectionData.d.ts +17 -10
- package/dist/utils/Command.cjs +9 -9
- package/dist/utils/CustomError.cjs +4 -0
- package/dist/utils/RuntimeNameHandler.cjs +1 -1
- package/dist/utils/Type.cjs +2 -1
- package/dist/utils/TypesHandler.cjs +55 -0
- package/dist/utils/UtilsConst.cjs +101 -0
- package/dist/utils/connectionData/IConnectionData.cjs +9 -0
- package/dist/utils/connectionData/InMemoryConnectionData.cjs +10 -0
- package/dist/utils/connectionData/WsConnectionData.cjs +4 -0
- package/dist/utils/nodejs/connectionData/TcpConnectionData.cjs +33 -3
- package/lib/core/delegatesCache/DelegatesCache.js +1 -0
- package/lib/core/handler/AbstractHandler.js +27 -9
- package/lib/core/handler/ArrayGetItemHandler.js +9 -1
- package/lib/core/handler/ArrayGetRankHandler.js +9 -0
- package/lib/core/handler/ArrayGetSizeHandler.js +8 -0
- package/lib/core/handler/ArrayHandler.js +8 -0
- package/lib/core/handler/ArraySetItemHandler.js +11 -1
- package/lib/core/handler/CastingHandler.js +8 -1
- package/lib/core/handler/ConvertTypeHandler.js +9 -4
- package/lib/core/handler/CreateClassInstanceHandler.js +10 -4
- package/lib/core/handler/DestructReferenceHandler.js +8 -0
- package/lib/core/handler/EnableNamespaceHandler.js +8 -0
- package/lib/core/handler/EnableTypeHandler.js +8 -0
- package/lib/core/handler/GetGlobalStaticFieldHandler.js +9 -0
- package/lib/core/handler/GetInstanceFieldHandler.js +8 -0
- package/lib/core/handler/GetInstanceMethodAsDelegateHandler.js +9 -4
- package/lib/core/handler/GetStaticFieldHandler.js +9 -0
- package/lib/core/handler/GetStaticMethodAsDelegateHandler.js +8 -7
- package/lib/core/handler/GetTypeHandler.js +15 -5
- package/lib/core/handler/Handler.js +13 -18
- package/lib/core/handler/InvokeDelegateHandler.js +5 -0
- package/lib/core/handler/InvokeGlobalFunctionHandler.js +11 -1
- package/lib/core/handler/InvokeInstanceMethodHandler.js +8 -0
- package/lib/core/handler/InvokeStaticMethodHandler.js +8 -0
- package/lib/core/handler/LoadLibraryHandler.js +11 -0
- package/lib/core/handler/SetGlobalStaticFieldHandler.js +10 -0
- package/lib/core/handler/SetInstanceFieldHandler.js +7 -0
- package/lib/core/handler/SetStaticFieldHandler.js +8 -0
- package/lib/core/handler/ValueHandler.js +9 -0
- package/lib/core/interpreter/Interpreter.js +42 -24
- package/lib/core/namespaceCache/NamespaceCache.js +14 -0
- package/lib/core/protocol/CommandDeserializer.js +11 -2
- package/lib/core/protocol/CommandSerializer.js +40 -9
- package/lib/core/protocol/TypeDeserializer.js +36 -0
- package/lib/core/protocol/TypeSerializer.js +62 -7
- package/lib/core/receiver/Receiver.js +3 -2
- package/lib/core/receiver/ReceiverNative.js +8 -0
- package/lib/core/transmitter/Transmitter.js +18 -1
- package/lib/core/transmitter/TransmitterWebsocket.js +12 -5
- package/lib/core/transmitter/TransmitterWebsocketBrowser.js +2 -4
- package/lib/core/transmitter/TransmitterWrapper.js +27 -6
- package/lib/core/typeCache/TypeCache.js +9 -0
- package/lib/core/webSocketClient/WebSocketClient.js +33 -30
- package/lib/core/webSocketClient/WebSocketClientBrowser.js +5 -6
- package/lib/sdk/ConfigRuntimeFactory.js +70 -68
- package/lib/sdk/InvocationContext.js +94 -26
- package/lib/sdk/Javonet.js +18 -36
- package/lib/sdk/RuntimeContext.js +109 -29
- package/lib/sdk/RuntimeFactory.js +7 -0
- package/lib/sdk/tools/ActivationHelper.js +51 -0
- package/lib/sdk/tools/JsonResolver.js +226 -0
- package/lib/types.d.ts +57 -0
- package/lib/utils/Command.js +14 -9
- package/lib/utils/CustomError.js +5 -0
- package/lib/utils/Runtime.js +1 -1
- package/lib/utils/RuntimeLogger.js +3 -0
- package/lib/utils/RuntimeNameHandler.js +6 -1
- package/lib/utils/Type.js +2 -1
- package/lib/utils/TypesHandler.js +35 -0
- package/lib/utils/UtilsConst.js +88 -0
- package/lib/utils/connectionData/IConnectionData.js +14 -0
- package/lib/utils/connectionData/InMemoryConnectionData.js +15 -0
- package/lib/utils/connectionData/WsConnectionData.js +9 -0
- package/lib/utils/nodejs/connectionData/TcpConnectionData.js +35 -5
- package/package.json +4 -3
- package/dist/sdk/tools/browser/ConfigSourceResolver.cjs +0 -153
- package/dist/sdk/tools/nodejs/JsonFileResolver.cjs +0 -120
- package/dist/types/sdk/tools/browser/ConfigSourceResolver.d.ts +0 -46
- package/dist/types/sdk/tools/nodejs/JsonFileResolver.d.ts +0 -13
- package/dist/types/utils/nodejs/TypesConverter.d.ts +0 -48
- package/dist/utils/nodejs/TypesConverter.cjs +0 -102
- package/lib/declarations.d.ts +0 -35
- package/lib/sdk/tools/browser/ConfigSourceResolver.js +0 -146
- package/lib/sdk/tools/nodejs/JsonFileResolver.js +0 -106
- package/lib/utils/nodejs/TypesConverter.js +0 -91
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var UtilsConst_exports = {};
|
|
20
|
+
__export(UtilsConst_exports, {
|
|
21
|
+
UtilsConst: () => UtilsConst
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(UtilsConst_exports);
|
|
24
|
+
var import_Runtime = require("./Runtime.cjs");
|
|
25
|
+
const import_meta = {};
|
|
26
|
+
let fs = null;
|
|
27
|
+
let path = null;
|
|
28
|
+
const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
|
|
29
|
+
class UtilsConst {
|
|
30
|
+
/** @type {string} */
|
|
31
|
+
static _javonetWorkingDirectory = ".";
|
|
32
|
+
/** @type {string} */
|
|
33
|
+
static _configSource = "";
|
|
34
|
+
/** @type {string} */
|
|
35
|
+
static _licenseKey = "";
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} inputPath
|
|
38
|
+
*/
|
|
39
|
+
static setJavonetWorkingDirectory(inputPath) {
|
|
40
|
+
if (!inputPath) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let normalizedPath = inputPath.replace(/\\/g, "/");
|
|
44
|
+
if (!normalizedPath.endsWith("/")) {
|
|
45
|
+
normalizedPath += "/";
|
|
46
|
+
}
|
|
47
|
+
if ((0, import_Runtime.isNodejsRuntime)()) {
|
|
48
|
+
if (!fs) {
|
|
49
|
+
fs = requireDynamic("fs");
|
|
50
|
+
}
|
|
51
|
+
if (!fs.existsSync(normalizedPath)) {
|
|
52
|
+
fs.mkdirSync(normalizedPath, { recursive: true });
|
|
53
|
+
fs.chmodSync(normalizedPath, 448);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
UtilsConst._javonetWorkingDirectory = normalizedPath;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
static getJavonetWorkingDirectory() {
|
|
62
|
+
if ((0, import_Runtime.isNodejsRuntime)() && !UtilsConst._javonetWorkingDirectory) {
|
|
63
|
+
if (!path) {
|
|
64
|
+
path = requireDynamic("path");
|
|
65
|
+
}
|
|
66
|
+
UtilsConst._javonetWorkingDirectory = path.resolve() + "/";
|
|
67
|
+
}
|
|
68
|
+
return UtilsConst._javonetWorkingDirectory;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} value
|
|
72
|
+
*/
|
|
73
|
+
static setConfigSource(value) {
|
|
74
|
+
UtilsConst._configSource = value;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
static getConfigSource() {
|
|
80
|
+
return UtilsConst._configSource;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} value
|
|
84
|
+
*/
|
|
85
|
+
static setLicenseKey(value) {
|
|
86
|
+
if (!value || value === "your-license-key") {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
UtilsConst._licenseKey = value;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
static getLicenseKey() {
|
|
95
|
+
return UtilsConst._licenseKey;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
UtilsConst
|
|
101
|
+
});
|
|
@@ -22,12 +22,21 @@ __export(IConnectionData_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(IConnectionData_exports);
|
|
24
24
|
class IConnectionData {
|
|
25
|
+
/**
|
|
26
|
+
* @returns {ConnectionType}
|
|
27
|
+
*/
|
|
25
28
|
get connectionType() {
|
|
26
29
|
throw new Error("You have to implement the method connectionType!");
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
28
34
|
get hostname() {
|
|
29
35
|
throw new Error("You have to implement the method hostname!");
|
|
30
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @returns {number[]}
|
|
39
|
+
*/
|
|
31
40
|
serializeConnectionData() {
|
|
32
41
|
throw new Error("You have to implement the method serializeConnectionData!");
|
|
33
42
|
}
|
|
@@ -29,12 +29,22 @@ class InMemoryConnectionData extends import_IConnectionData.IConnectionData {
|
|
|
29
29
|
this._connectionType = import_ConnectionType.ConnectionType.IN_MEMORY;
|
|
30
30
|
this._hostname = "";
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* @returns {ConnectionType}
|
|
34
|
+
*/
|
|
32
35
|
get connectionType() {
|
|
33
36
|
return this._connectionType;
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
35
41
|
get hostname() {
|
|
36
42
|
return this._hostname;
|
|
37
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Serializes the connection data.
|
|
46
|
+
* @returns {number[]} An array of connection data values.
|
|
47
|
+
*/
|
|
38
48
|
serializeConnectionData() {
|
|
39
49
|
return [this.connectionType, 0, 0, 0, 0, 0, 0];
|
|
40
50
|
}
|
|
@@ -51,6 +51,10 @@ class WsConnectionData extends import_IConnectionData.IConnectionData {
|
|
|
51
51
|
serializeConnectionData() {
|
|
52
52
|
return [this.connectionType, 0, 0, 0, 0, 0, 0];
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {WsConnectionData} other
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
54
58
|
equals(other) {
|
|
55
59
|
return other instanceof WsConnectionData && this._hostname === other.hostname;
|
|
56
60
|
}
|
|
@@ -27,6 +27,18 @@ var import_Runtime = require("../../Runtime.cjs");
|
|
|
27
27
|
const import_meta = {};
|
|
28
28
|
const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
|
|
29
29
|
class TcpConnectionData extends import_IConnectionData.IConnectionData {
|
|
30
|
+
/** @type {string} */
|
|
31
|
+
ipAddress = "";
|
|
32
|
+
/** @type {number} */
|
|
33
|
+
_port = 0;
|
|
34
|
+
/** @type {string} */
|
|
35
|
+
_hostname = "";
|
|
36
|
+
/** @type {ConnectionType} */
|
|
37
|
+
_connectionType = import_ConnectionType.ConnectionType.TCP;
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} hostname
|
|
40
|
+
* @param {number} port
|
|
41
|
+
*/
|
|
30
42
|
constructor(hostname, port) {
|
|
31
43
|
super();
|
|
32
44
|
this._port = port;
|
|
@@ -38,6 +50,9 @@ class TcpConnectionData extends import_IConnectionData.IConnectionData {
|
|
|
38
50
|
this.ipAddress = this.resolveIpAddress(hostname);
|
|
39
51
|
}
|
|
40
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @returns {ConnectionType}
|
|
55
|
+
*/
|
|
41
56
|
get connectionType() {
|
|
42
57
|
return this._connectionType;
|
|
43
58
|
}
|
|
@@ -56,7 +71,7 @@ class TcpConnectionData extends import_IConnectionData.IConnectionData {
|
|
|
56
71
|
}
|
|
57
72
|
/**
|
|
58
73
|
* @param {string} hostname
|
|
59
|
-
* @returns {string
|
|
74
|
+
* @returns {string}
|
|
60
75
|
*/
|
|
61
76
|
resolveIpAddress(hostname) {
|
|
62
77
|
try {
|
|
@@ -69,28 +84,43 @@ class TcpConnectionData extends import_IConnectionData.IConnectionData {
|
|
|
69
84
|
return dns.resolve4(hostname, (err, addresses) => {
|
|
70
85
|
if (err) {
|
|
71
86
|
console.error(err);
|
|
72
|
-
return
|
|
87
|
+
return "";
|
|
73
88
|
}
|
|
74
89
|
return addresses[0];
|
|
75
90
|
});
|
|
76
91
|
}
|
|
77
92
|
}
|
|
93
|
+
return "";
|
|
78
94
|
} catch (error) {
|
|
79
|
-
|
|
95
|
+
const err = (
|
|
96
|
+
/** @type {{code?: string}} */
|
|
97
|
+
error
|
|
98
|
+
);
|
|
99
|
+
if (err.code === "MODULE_NOT_FOUND") {
|
|
80
100
|
throw new Error("dns module not found. Please install it using npm install dns");
|
|
81
101
|
}
|
|
82
102
|
throw error;
|
|
83
103
|
}
|
|
84
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Serializes the connection data.
|
|
107
|
+
* @returns {number[]} An array of connection data values.
|
|
108
|
+
*/
|
|
85
109
|
serializeConnectionData() {
|
|
86
110
|
let result = [this.connectionType];
|
|
87
111
|
result = result.concat(this.#getAddressBytes());
|
|
88
112
|
result = result.concat(this.#getPortBytes());
|
|
89
113
|
return result;
|
|
90
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* @returns {number[]} An array of address bytes.
|
|
117
|
+
*/
|
|
91
118
|
#getAddressBytes() {
|
|
92
119
|
return this.ipAddress.split(".").map(Number);
|
|
93
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* @returns {number[]} An array of port bytes.
|
|
123
|
+
*/
|
|
94
124
|
#getPortBytes() {
|
|
95
125
|
return [this._port & 255, this._port >> 8];
|
|
96
126
|
}
|
|
@@ -1,36 +1,54 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { Command } from '../../utils/Command.js'
|
|
2
3
|
|
|
3
4
|
class AbstractHandler {
|
|
5
|
+
/**
|
|
6
|
+
* @type {Record<number, AbstractHandler>}
|
|
7
|
+
*/
|
|
4
8
|
handlers = []
|
|
5
9
|
|
|
6
10
|
constructor() {
|
|
7
11
|
if (new.target === AbstractHandler) throw new TypeError('You cannot instantiate abstract class')
|
|
8
12
|
}
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @param {Command} command
|
|
16
|
+
*/
|
|
11
17
|
process(command) {
|
|
12
18
|
throw new Error('process must be implemented')
|
|
13
19
|
}
|
|
14
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @param {Command} command
|
|
23
|
+
*/
|
|
15
24
|
handleCommand(command) {
|
|
16
25
|
this.iterate(command)
|
|
17
26
|
return this.process(command)
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
/**
|
|
30
|
+
* @param {Command} command
|
|
31
|
+
*/
|
|
32
|
+
iterate(command) {
|
|
33
|
+
for (let i = 0; i < command.payload.length; i++) {
|
|
34
|
+
if (command.payload[i] instanceof Command) {
|
|
35
|
+
let inner = command.payload[i]
|
|
36
|
+
command.payload[i] = this.handlers[inner.commandType].handleCommand(inner)
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
39
|
}
|
|
28
40
|
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param {*} error
|
|
44
|
+
* @param {*} class_name
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
29
47
|
process_stack_trace(error, class_name) {
|
|
30
|
-
let stackTraceArray = error.stack.split('\n').map((frame) => frame.trim())
|
|
31
|
-
stackTraceArray.forEach((str, index) => {
|
|
48
|
+
let stackTraceArray = error.stack.split('\n').map((/** @type {string} */ frame) => frame.trim())
|
|
49
|
+
stackTraceArray.forEach((/** @type {string} */ str, /** @type {number} */ index) => {
|
|
32
50
|
if (str.includes(class_name)) {
|
|
33
|
-
stackTraceArray = stackTraceArray.slice(0, index).filter((s) => !s.includes(class_name))
|
|
51
|
+
stackTraceArray = stackTraceArray.slice(0, index).filter((/** @type {string} */ s) => !s.includes(class_name))
|
|
34
52
|
}
|
|
35
53
|
})
|
|
36
54
|
error.stack = stackTraceArray.join(' \n ')
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class ArrayGetItemHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 2
|
|
5
10
|
|
|
@@ -7,6 +12,9 @@ class ArrayGetItemHandler extends AbstractHandler {
|
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -21,7 +29,7 @@ class ArrayGetItemHandler extends AbstractHandler {
|
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
if (indexes.length === 1) {
|
|
24
|
-
return array[indexes]
|
|
32
|
+
return array[indexes[0]]
|
|
25
33
|
} else {
|
|
26
34
|
let array_copy = [...array]
|
|
27
35
|
for (let i = 0; i < indexes.length; i++) {
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class ArrayGetRankHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 1
|
|
5
10
|
|
|
6
11
|
constructor() {
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
9
18
|
process(command) {
|
|
10
19
|
try {
|
|
11
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class ArrayGetSizeHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 1
|
|
5
10
|
|
|
@@ -7,6 +12,9 @@ class ArrayGetSizeHandler extends AbstractHandler {
|
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class ArrayHandler extends AbstractHandler {
|
|
4
9
|
constructor() {
|
|
5
10
|
super()
|
|
6
11
|
}
|
|
7
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @param {Command} command
|
|
15
|
+
*/
|
|
8
16
|
process(command) {
|
|
9
17
|
try {
|
|
10
18
|
let processedArray = command.payload
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class ArraySetItemHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 3
|
|
5
10
|
|
|
@@ -7,6 +12,9 @@ class ArraySetItemHandler extends AbstractHandler {
|
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -15,6 +23,8 @@ class ArraySetItemHandler extends AbstractHandler {
|
|
|
15
23
|
|
|
16
24
|
let array = command.payload[0]
|
|
17
25
|
let value = command.payload[2]
|
|
26
|
+
|
|
27
|
+
/** @type {number[]} */
|
|
18
28
|
let indexes
|
|
19
29
|
if (Array.isArray(command.payload[1])) {
|
|
20
30
|
indexes = command.payload[1]
|
|
@@ -24,7 +34,7 @@ class ArraySetItemHandler extends AbstractHandler {
|
|
|
24
34
|
|
|
25
35
|
if (indexes.length === 1) {
|
|
26
36
|
// one-dimensional array
|
|
27
|
-
array[indexes] = value
|
|
37
|
+
array[indexes[0]] = value
|
|
28
38
|
} else {
|
|
29
39
|
// multi-dimensional array
|
|
30
40
|
for (let i = 0; i < indexes.length - 1; i++) {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class CastingHandler extends AbstractHandler {
|
|
4
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {Command} command
|
|
11
|
+
*/
|
|
5
12
|
process(command) {
|
|
6
13
|
throw new Error(`Dynamically typed languages are not supporting casting`)
|
|
7
14
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { TypesHandler } from '../../utils/TypesHandler.js'
|
|
2
3
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* ConvertTypeHandler class handles the conversion of JType to Type.
|
|
6
11
|
*/
|
|
@@ -16,17 +21,17 @@ class ConvertTypeHandler extends AbstractHandler {
|
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
23
|
* Processes the given command to convert JType to Type.
|
|
19
|
-
* @param {
|
|
24
|
+
* @param {Command} command - The command to process.
|
|
20
25
|
* @returns {any} The converted type.
|
|
21
26
|
*/
|
|
22
27
|
process(command) {
|
|
23
28
|
this.validateCommand(command)
|
|
24
|
-
return
|
|
29
|
+
return TypesHandler.convertTypeToJType(command.payload[0])
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* Validates the command to ensure it has enough parameters.
|
|
29
|
-
* @param {
|
|
34
|
+
* @param {Command} command - The command to validate.
|
|
30
35
|
*/
|
|
31
36
|
validateCommand(command) {
|
|
32
37
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class CreateClassInstanceHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 1
|
|
5
10
|
|
|
@@ -7,6 +12,9 @@ class CreateClassInstanceHandler extends AbstractHandler {
|
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -16,10 +24,8 @@ class CreateClassInstanceHandler extends AbstractHandler {
|
|
|
16
24
|
let constructorArguments = command.payload.slice(1)
|
|
17
25
|
let instance = new clazz(...constructorArguments)
|
|
18
26
|
if (typeof instance === 'undefined') {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line no-undef
|
|
22
|
-
return typeof type[property] === 'function'
|
|
27
|
+
let methods = Object.getOwnPropertyNames(clazz).filter(function (property) {
|
|
28
|
+
return typeof clazz[property] === 'function'
|
|
23
29
|
})
|
|
24
30
|
let message = `Method 'constructor' not found in class. Available methods:\n`
|
|
25
31
|
methods.forEach((methodIter) => {
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { ReferencesCache } from '../referenceCache/ReferencesCache.js'
|
|
2
3
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
class DestructReferenceHandler extends AbstractHandler {
|
|
5
10
|
constructor() {
|
|
6
11
|
super()
|
|
7
12
|
}
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {Command} command
|
|
16
|
+
*/
|
|
9
17
|
process(command) {
|
|
10
18
|
try {
|
|
11
19
|
let cache = ReferencesCache.getInstance()
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { NamespaceCache } from '../namespaceCache/NamespaceCache.js'
|
|
2
3
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
class EnableNamespaceHandler extends AbstractHandler {
|
|
5
10
|
constructor() {
|
|
6
11
|
super()
|
|
7
12
|
this.requiredParametersCount = 1
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { TypeCache } from '../typeCache/TypeCache.js'
|
|
2
3
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
class EnableTypeHandler extends AbstractHandler {
|
|
5
10
|
requiredParametersCount = 1
|
|
6
11
|
|
|
@@ -8,6 +13,9 @@ class EnableTypeHandler extends AbstractHandler {
|
|
|
8
13
|
super()
|
|
9
14
|
}
|
|
10
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @param {Command} command
|
|
18
|
+
*/
|
|
11
19
|
process(command) {
|
|
12
20
|
try {
|
|
13
21
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class GetGlobalStaticFieldHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 1
|
|
5
10
|
|
|
@@ -7,6 +12,9 @@ class GetGlobalStaticFieldHandler extends AbstractHandler {
|
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -17,6 +25,7 @@ class GetGlobalStaticFieldHandler extends AbstractHandler {
|
|
|
17
25
|
let fieldToGet
|
|
18
26
|
|
|
19
27
|
for (let i = 0; i < splitted.length; i++) {
|
|
28
|
+
// @ts-expect-error
|
|
20
29
|
fieldToGet = !fieldToGet ? global[splitted[i]] : fieldToGet[splitted[i]]
|
|
21
30
|
if (typeof fieldToGet === 'undefined') {
|
|
22
31
|
let fields = Object.keys(global)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../utils/Command.js').Command} Command
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
class GetInstanceFieldHandler extends AbstractHandler {
|
|
4
9
|
requiredParametersCount = 2
|
|
5
10
|
|
|
@@ -7,6 +12,9 @@ class GetInstanceFieldHandler extends AbstractHandler {
|
|
|
7
12
|
super()
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {Command} command
|
|
17
|
+
*/
|
|
10
18
|
process(command) {
|
|
11
19
|
try {
|
|
12
20
|
if (command.payload.length < this.requiredParametersCount) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { AbstractHandler } from './AbstractHandler.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -32,6 +33,10 @@ class GetInstanceMethodAsDelegateHandler extends AbstractHandler {
|
|
|
32
33
|
const methodName = command.payload[1]
|
|
33
34
|
this.args = command.payload.length > 2 ? command.payload.slice(2) : []
|
|
34
35
|
|
|
36
|
+
if (!this.instance) {
|
|
37
|
+
throw new Error('Instance is null or undefined')
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
// Find the method on the instance
|
|
36
41
|
this.method = this.getMethod(this.instance, methodName)
|
|
37
42
|
if (!this.method) {
|
|
@@ -50,7 +55,7 @@ class GetInstanceMethodAsDelegateHandler extends AbstractHandler {
|
|
|
50
55
|
* @returns {Function|null} The found method or null if not found.
|
|
51
56
|
*/
|
|
52
57
|
getMethod(type, methodName) {
|
|
53
|
-
const method = type[methodName]
|
|
58
|
+
const method = /** @type {any} */ (type)[methodName]
|
|
54
59
|
return typeof method === 'function' ? method : null
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -61,11 +66,11 @@ class GetInstanceMethodAsDelegateHandler extends AbstractHandler {
|
|
|
61
66
|
* @returns {Error} The error with detailed message.
|
|
62
67
|
*/
|
|
63
68
|
createMethodNotFoundError(type, methodName) {
|
|
64
|
-
const methods = Object.getOwnPropertyNames(type.prototype).filter(
|
|
65
|
-
(key) => typeof type.prototype[key] === 'function'
|
|
69
|
+
const methods = Object.getOwnPropertyNames(/** @type {{prototype: Object}} */ (type).prototype).filter(
|
|
70
|
+
(key) => typeof /** @type {any} */ (type).prototype[key] === 'function'
|
|
66
71
|
)
|
|
67
72
|
const availableMethods = methods.map((name) => `${name}()`)
|
|
68
|
-
const message = `Method ${methodName} not found in class ${type.name}. Available instance public methods:\n${availableMethods.join('\n')}`
|
|
73
|
+
const message = `Method ${methodName} not found in class ${/** @type {{name: string}} */ (type).name}. Available instance public methods:\n${availableMethods.join('\n')}`
|
|
69
74
|
return new Error(message)
|
|
70
75
|
}
|
|
71
76
|
}
|