javonet-nodejs-sdk 2.6.10 → 2.6.11
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/Handler.cjs +12 -10
- package/dist/core/handler/PassDelegateHandler.cjs +13 -5
- package/dist/core/interpreter/Interpreter.cjs +4 -13
- package/dist/core/protocol/CommandDeserializer.cjs +1 -1
- package/dist/core/protocol/CommandSerializer.cjs +5 -5
- package/dist/core/receiver/Receiver.cjs +4 -7
- package/dist/sdk/InvocationContext.cjs +5 -7
- package/dist/sdk/Javonet.cjs +3 -1
- package/dist/sdk/RuntimeContext.cjs +29 -11
- package/dist/sdk/RuntimeFactory.cjs +0 -22
- package/dist/types/core/handler/Handler.d.ts +11 -11
- package/dist/types/core/handler/PassDelegateHandler.d.ts +0 -5
- package/dist/types/core/interpreter/Interpreter.d.ts +2 -7
- package/dist/types/core/protocol/CommandSerializer.d.ts +2 -2
- package/dist/types/core/receiver/Receiver.d.ts +0 -1
- package/dist/types/sdk/Javonet.d.ts +2 -2
- package/dist/types/sdk/RuntimeContext.d.ts +8 -3
- package/dist/types/sdk/RuntimeFactory.d.ts +0 -8
- package/lib/core/handler/Handler.js +16 -13
- package/lib/core/handler/PassDelegateHandler.js +3 -7
- package/lib/core/interpreter/Interpreter.js +4 -14
- package/lib/core/protocol/CommandDeserializer.js +1 -1
- package/lib/core/protocol/CommandSerializer.js +5 -5
- package/lib/core/receiver/Receiver.js +4 -6
- package/lib/sdk/InvocationContext.js +7 -8
- package/lib/sdk/Javonet.js +2 -1
- package/lib/sdk/RuntimeContext.js +42 -13
- package/lib/sdk/RuntimeFactory.js +0 -34
- package/package.json +1 -1
|
@@ -131,31 +131,33 @@ const handlers = {
|
|
|
131
131
|
[import_CommandType.CommandType.ValueForUpdate]: new import_ValueForUpdateHandler.ValueForUpdateHandler()
|
|
132
132
|
};
|
|
133
133
|
class Handler {
|
|
134
|
+
static _initialized = false;
|
|
134
135
|
/**
|
|
135
|
-
*
|
|
136
|
+
* Initializes the handlers map. This is called lazily on first use.
|
|
136
137
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
throw new Error("interpreter is undefined in Handler constructor");
|
|
138
|
+
static _initialize() {
|
|
139
|
+
if (Handler._initialized) {
|
|
140
|
+
return;
|
|
141
141
|
}
|
|
142
|
-
handlers[import_CommandType.CommandType.PassDelegate] = new import_PassDelegateHandler.PassDelegateHandler(
|
|
142
|
+
handlers[import_CommandType.CommandType.PassDelegate] = new import_PassDelegateHandler.PassDelegateHandler();
|
|
143
143
|
Object.keys(handlers).forEach((commandTypeHandler) => {
|
|
144
144
|
handlers[commandTypeHandler].handlers = handlers;
|
|
145
145
|
});
|
|
146
|
+
Handler._initialized = true;
|
|
146
147
|
}
|
|
147
148
|
/**
|
|
148
149
|
* @param {Command} command
|
|
149
150
|
* @returns {Promise<Command> | Command}
|
|
150
151
|
*/
|
|
151
|
-
handleCommand(command) {
|
|
152
|
+
static handleCommand(command) {
|
|
153
|
+
Handler._initialize();
|
|
152
154
|
try {
|
|
153
155
|
if (command.commandType === import_CommandType.CommandType.RetrieveArray) {
|
|
154
156
|
const responseArray = handlers[import_CommandType.CommandType.Reference].handleCommand(command.payload[0]);
|
|
155
157
|
return import_Command.Command.createArrayResponse(responseArray, command.runtimeName);
|
|
156
158
|
}
|
|
157
159
|
const response = handlers[command.commandType].handleCommand(command);
|
|
158
|
-
return
|
|
160
|
+
return Handler.parseCommand(response, command.runtimeName);
|
|
159
161
|
} catch (e) {
|
|
160
162
|
return Handler.resolveException(e, command);
|
|
161
163
|
}
|
|
@@ -175,10 +177,10 @@ class Handler {
|
|
|
175
177
|
* @param {RuntimeName} runtimeName
|
|
176
178
|
* @returns {Promise<Command> | Command}
|
|
177
179
|
*/
|
|
178
|
-
parseCommand(response, runtimeName) {
|
|
180
|
+
static parseCommand(response, runtimeName) {
|
|
179
181
|
if (response instanceof Promise) {
|
|
180
182
|
return response.then((resolvedResponse) => {
|
|
181
|
-
return
|
|
183
|
+
return Handler.parseCommand(resolvedResponse, runtimeName);
|
|
182
184
|
});
|
|
183
185
|
}
|
|
184
186
|
let responseCommand;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var PassDelegateHandler_exports = {};
|
|
20
30
|
__export(PassDelegateHandler_exports, {
|
|
@@ -26,12 +36,9 @@ var import_InMemoryConnectionData = require("../../utils/connectionData/InMemory
|
|
|
26
36
|
var import_DelegatesCache = require("../delegatesCache/DelegatesCache.cjs");
|
|
27
37
|
var import_AbstractHandler = require("./AbstractHandler.cjs");
|
|
28
38
|
class PassDelegateHandler extends import_AbstractHandler.AbstractHandler {
|
|
29
|
-
|
|
30
|
-
interpreter = null;
|
|
31
|
-
constructor(interpreter = null) {
|
|
39
|
+
constructor() {
|
|
32
40
|
super();
|
|
33
41
|
this.requiredParametersCount = 1;
|
|
34
|
-
this.interpreter = interpreter;
|
|
35
42
|
}
|
|
36
43
|
/**S
|
|
37
44
|
* Processes the given command to create and compile a delegate.
|
|
@@ -113,7 +120,8 @@ class PassDelegateHandler extends import_AbstractHandler.AbstractHandler {
|
|
|
113
120
|
* @returns {Promise<any>} The response object.
|
|
114
121
|
*/
|
|
115
122
|
async createExecuteCall(command) {
|
|
116
|
-
|
|
123
|
+
const { Interpreter } = await import("../interpreter/Interpreter.js");
|
|
124
|
+
return Interpreter.execute(command, new import_InMemoryConnectionData.InMemoryConnectionData());
|
|
117
125
|
}
|
|
118
126
|
/**
|
|
119
127
|
* Retrieves the response payload from the execution call.
|
|
@@ -35,24 +35,15 @@ let _Transmitter;
|
|
|
35
35
|
let _TransmitterWebsocket = (0, import_Runtime.isNodejsRuntime)() ? import_TransmitterWebsocket.TransmitterWebsocket : import_TransmitterWebsocketBrowser.TransmitterWebsocketBrowser;
|
|
36
36
|
const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
|
|
37
37
|
class Interpreter {
|
|
38
|
-
/** @type {Handler | null} */
|
|
39
|
-
_handler = null;
|
|
40
|
-
/** @type {Handler} */
|
|
41
|
-
get handler() {
|
|
42
|
-
if (!this._handler) {
|
|
43
|
-
this._handler = new import_Handler.Handler(this);
|
|
44
|
-
}
|
|
45
|
-
return this._handler;
|
|
46
|
-
}
|
|
47
38
|
/**
|
|
48
39
|
*
|
|
49
40
|
* @param {Command} command
|
|
50
41
|
* @param {IConnectionData} connectionData
|
|
51
42
|
* @returns {Promise<Command>}
|
|
52
43
|
*/
|
|
53
|
-
async execute(command, connectionData) {
|
|
44
|
+
static async execute(command, connectionData) {
|
|
54
45
|
try {
|
|
55
|
-
let messageByteArray =
|
|
46
|
+
let messageByteArray = import_CommandSerializer.CommandSerializer.serialize(command, connectionData);
|
|
56
47
|
if (!(messageByteArray instanceof Uint8Array)) {
|
|
57
48
|
throw new Error("Serialized message is not Uint8Array");
|
|
58
49
|
}
|
|
@@ -96,10 +87,10 @@ class Interpreter {
|
|
|
96
87
|
* @param {Uint8Array} messageByteArray
|
|
97
88
|
* @returns {Promise<Command> | Command}
|
|
98
89
|
*/
|
|
99
|
-
process(messageByteArray) {
|
|
90
|
+
static process(messageByteArray) {
|
|
100
91
|
try {
|
|
101
92
|
const receivedCommand = new import_CommandDeserializer.CommandDeserializer(messageByteArray).deserialize();
|
|
102
|
-
return
|
|
93
|
+
return import_Handler.Handler.handleCommand(receivedCommand);
|
|
103
94
|
} catch (error) {
|
|
104
95
|
throw error;
|
|
105
96
|
}
|
|
@@ -73,7 +73,7 @@ class CommandDeserializer {
|
|
|
73
73
|
case "JAVONET_DOUBLE":
|
|
74
74
|
return this.readDouble();
|
|
75
75
|
case "JAVONET_UNSIGNED_LONG_LONG":
|
|
76
|
-
return this.readUllong;
|
|
76
|
+
return this.readUllong();
|
|
77
77
|
case "JAVONET_UNSIGNED_INTEGER":
|
|
78
78
|
return this.readUInt();
|
|
79
79
|
case "JAVONET_NULL":
|
|
@@ -35,7 +35,7 @@ class CommandSerializer {
|
|
|
35
35
|
* @param {number} runtimeVersion
|
|
36
36
|
* @returns {Uint8Array}
|
|
37
37
|
*/
|
|
38
|
-
serialize(rootCommand, connectionData, runtimeVersion = 0) {
|
|
38
|
+
static serialize(rootCommand, connectionData, runtimeVersion = 0) {
|
|
39
39
|
const buffers = [];
|
|
40
40
|
buffers.push(Uint8Array.of(rootCommand.runtimeName, runtimeVersion));
|
|
41
41
|
if (connectionData) {
|
|
@@ -44,7 +44,7 @@ class CommandSerializer {
|
|
|
44
44
|
buffers.push(Uint8Array.of(0, 0, 0, 0, 0, 0, 0));
|
|
45
45
|
}
|
|
46
46
|
buffers.push(Uint8Array.of(import_RuntimeName.RuntimeName.Python, rootCommand.commandType));
|
|
47
|
-
|
|
47
|
+
CommandSerializer.serializeRecursively(rootCommand, buffers);
|
|
48
48
|
return concatenateUint8Arrays(buffers);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
@@ -52,18 +52,18 @@ class CommandSerializer {
|
|
|
52
52
|
* @param {Command} command
|
|
53
53
|
* @param {Array<Uint8Array>} buffers
|
|
54
54
|
*/
|
|
55
|
-
serializeRecursively(command, buffers) {
|
|
55
|
+
static serializeRecursively(command, buffers) {
|
|
56
56
|
for (const item of command.payload) {
|
|
57
57
|
if (item instanceof import_Command.Command) {
|
|
58
58
|
buffers.push(import_TypeSerializer.TypeSerializer.serializeCommand(item));
|
|
59
|
-
|
|
59
|
+
CommandSerializer.serializeRecursively(item, buffers);
|
|
60
60
|
} else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(item)) {
|
|
61
61
|
buffers.push(import_TypeSerializer.TypeSerializer.serializePrimitive(item));
|
|
62
62
|
} else {
|
|
63
63
|
const cachedReference = import_ReferencesCache.ReferencesCache.getInstance().cacheReference(item);
|
|
64
64
|
const refCommand = new import_Command.Command(import_RuntimeName.RuntimeName.Nodejs, import_CommandType.CommandType.Reference, cachedReference);
|
|
65
65
|
buffers.push(import_TypeSerializer.TypeSerializer.serializeCommand(refCommand));
|
|
66
|
-
|
|
66
|
+
CommandSerializer.serializeRecursively(refCommand, buffers);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -21,19 +21,16 @@ __export(Receiver_exports, {
|
|
|
21
21
|
Receiver: () => Receiver
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(Receiver_exports);
|
|
24
|
-
var import_Interpreter = require("../interpreter/Interpreter.cjs");
|
|
25
24
|
var import_CommandSerializer = require("../protocol/CommandSerializer.cjs");
|
|
26
|
-
var import_Runtime = require("../../utils/Runtime.cjs");
|
|
27
25
|
var import_InMemoryConnectionData = require("../../utils/connectionData/InMemoryConnectionData.cjs");
|
|
28
26
|
var import_ExceptionSerializer = require("../../utils/exception/ExceptionSerializer.cjs");
|
|
29
27
|
var import_Command = require("../../utils/Command.cjs");
|
|
30
28
|
var import_CommandType = require("../../utils/CommandType.cjs");
|
|
31
29
|
var import_RuntimeName = require("../../utils/RuntimeName.cjs");
|
|
32
30
|
var import_RuntimeLogger = require("../../utils/RuntimeLogger.cjs");
|
|
31
|
+
var import_Interpreter = require("./../interpreter/Interpreter.cjs");
|
|
33
32
|
class Receiver {
|
|
34
33
|
static connectionData = new import_InMemoryConnectionData.InMemoryConnectionData();
|
|
35
|
-
Receiver() {
|
|
36
|
-
}
|
|
37
34
|
static getRuntimeInfo() {
|
|
38
35
|
return import_RuntimeLogger.RuntimeLogger.getRuntimeInfo();
|
|
39
36
|
}
|
|
@@ -43,14 +40,14 @@ class Receiver {
|
|
|
43
40
|
*/
|
|
44
41
|
static async sendCommand(messageByteArray) {
|
|
45
42
|
try {
|
|
46
|
-
let command = await
|
|
47
|
-
return
|
|
43
|
+
let command = await import_Interpreter.Interpreter.process(messageByteArray);
|
|
44
|
+
return import_CommandSerializer.CommandSerializer.serialize(command, this.connectionData);
|
|
48
45
|
} catch (error) {
|
|
49
46
|
const exceptionCommand = import_ExceptionSerializer.ExceptionSerializer.serializeException(
|
|
50
47
|
error,
|
|
51
48
|
new import_Command.Command(import_RuntimeName.RuntimeName.Nodejs, import_CommandType.CommandType.Exception, [])
|
|
52
49
|
);
|
|
53
|
-
return
|
|
50
|
+
return import_CommandSerializer.CommandSerializer.serialize(exceptionCommand, this.connectionData);
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
/**
|
|
@@ -52,14 +52,13 @@ class InvocationContext {
|
|
|
52
52
|
#responseCommand = null;
|
|
53
53
|
/** @type {boolean} */
|
|
54
54
|
#isExecuted = false;
|
|
55
|
-
/** @type {Interpreter | null} */
|
|
56
|
-
#interpreter = null;
|
|
57
55
|
/** @type {string | null} */
|
|
58
56
|
#guid = null;
|
|
59
57
|
/** @type {AsyncLock} */
|
|
60
58
|
#materializationLock = new AsyncLock();
|
|
61
59
|
// Static map holding contexts waiting for materialization (guid -> InvocationContext)
|
|
62
60
|
static _invocationContexts = /* @__PURE__ */ new Map();
|
|
61
|
+
//
|
|
63
62
|
/**
|
|
64
63
|
*
|
|
65
64
|
* @param {RuntimeNameType} runtimeName
|
|
@@ -73,7 +72,6 @@ class InvocationContext {
|
|
|
73
72
|
this.#currentCommand = command;
|
|
74
73
|
this.#responseCommand = null;
|
|
75
74
|
this.#isExecuted = isExecuted;
|
|
76
|
-
this.#interpreter = null;
|
|
77
75
|
this.#guid = (0, import_uuid.v4)();
|
|
78
76
|
}
|
|
79
77
|
/**
|
|
@@ -134,9 +132,6 @@ class InvocationContext {
|
|
|
134
132
|
if (this.#currentCommand === null) {
|
|
135
133
|
throw new Error("currentCommand is undefined in Invocation Context execute method");
|
|
136
134
|
}
|
|
137
|
-
if (!this.#interpreter) {
|
|
138
|
-
this.#interpreter = new import_Interpreter.Interpreter();
|
|
139
|
-
}
|
|
140
135
|
const entries = Array.from(InvocationContext._invocationContexts.entries());
|
|
141
136
|
entries.sort((a, b) => String(a[0]).localeCompare(String(b[0])));
|
|
142
137
|
const releases = [];
|
|
@@ -145,7 +140,10 @@ class InvocationContext {
|
|
|
145
140
|
releases.push(release);
|
|
146
141
|
}
|
|
147
142
|
try {
|
|
148
|
-
this.#responseCommand = await
|
|
143
|
+
this.#responseCommand = await import_Interpreter.Interpreter.execute(
|
|
144
|
+
this.#currentCommand,
|
|
145
|
+
this.#connectionData
|
|
146
|
+
);
|
|
149
147
|
if (!this.#responseCommand) {
|
|
150
148
|
throw new Error("responseCommand is undefined in Invocation Context execute method");
|
|
151
149
|
}
|
package/dist/sdk/Javonet.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(Javonet_exports, {
|
|
|
23
23
|
ComplexTypeResolver: () => import_ComplexTypeResolver.ComplexTypeResolver,
|
|
24
24
|
ConfigPriority: () => import_ConfigPriority.ConfigPriority,
|
|
25
25
|
Javonet: () => Javonet,
|
|
26
|
+
RuntimeContext: () => import_RuntimeContext.RuntimeContext,
|
|
26
27
|
TcpConnectionData: () => import_TcpConnectionData.TcpConnectionData,
|
|
27
28
|
WsConnectionData: () => import_WsConnectionData.WsConnectionData
|
|
28
29
|
});
|
|
@@ -129,7 +130,7 @@ class Javonet {
|
|
|
129
130
|
*/
|
|
130
131
|
static initializeRc(configName) {
|
|
131
132
|
const config = import_ConfigSourceResolver.ConfigSourceResolver.getConfig(configName);
|
|
132
|
-
return
|
|
133
|
+
return import_RuntimeContext.RuntimeContext.initializeRuntimeContext(config);
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -139,6 +140,7 @@ class Javonet {
|
|
|
139
140
|
ComplexTypeResolver,
|
|
140
141
|
ConfigPriority,
|
|
141
142
|
Javonet,
|
|
143
|
+
RuntimeContext,
|
|
142
144
|
TcpConnectionData,
|
|
143
145
|
WsConnectionData
|
|
144
146
|
});
|
|
@@ -31,6 +31,7 @@ var import_Interpreter = require("../core/interpreter/Interpreter.cjs");
|
|
|
31
31
|
var import_DelegatesCache = require("../core/delegatesCache/DelegatesCache.cjs");
|
|
32
32
|
var import_TypesHandler = require("../utils/TypesHandler.cjs");
|
|
33
33
|
var import_UtilsConst = require("../utils/UtilsConst.cjs");
|
|
34
|
+
var import_Config = require("./configuration/Config.cjs");
|
|
34
35
|
var import_Runtime = require("../utils/Runtime.cjs");
|
|
35
36
|
const import_meta = {};
|
|
36
37
|
let _Transmitter = null;
|
|
@@ -46,8 +47,6 @@ class RuntimeContext {
|
|
|
46
47
|
#currentCommand = null;
|
|
47
48
|
/** @type {Command | null} */
|
|
48
49
|
#responseCommand = null;
|
|
49
|
-
/** @type {Interpreter | null} */
|
|
50
|
-
#interpreter = null;
|
|
51
50
|
/**
|
|
52
51
|
* @param {RuntimeNameType} runtimeName
|
|
53
52
|
* @param {IConnectionData} connectionData
|
|
@@ -56,7 +55,6 @@ class RuntimeContext {
|
|
|
56
55
|
this._isExecuted = false;
|
|
57
56
|
this.runtimeName = runtimeName;
|
|
58
57
|
this.connectionData = connectionData;
|
|
59
|
-
this.#interpreter = new import_Interpreter.Interpreter();
|
|
60
58
|
if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
|
|
61
59
|
return;
|
|
62
60
|
}
|
|
@@ -69,6 +67,28 @@ class RuntimeContext {
|
|
|
69
67
|
}
|
|
70
68
|
_Transmitter?.activate(import_UtilsConst.UtilsConst.getLicenseKey());
|
|
71
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* @param {Config} config
|
|
72
|
+
* @returns {RuntimeContext}
|
|
73
|
+
*/
|
|
74
|
+
static initializeRuntimeContext(config) {
|
|
75
|
+
const rtmCtx = RuntimeContext.getInstance(config.runtime, config.connectionData);
|
|
76
|
+
if (config.connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
|
|
77
|
+
const modules = (config.modules || "").split(",").map((m) => m.trim()).filter((m) => m !== "");
|
|
78
|
+
let pathModule = null;
|
|
79
|
+
try {
|
|
80
|
+
const _require = typeof require !== "undefined" ? require : eval("require");
|
|
81
|
+
pathModule = _require("path");
|
|
82
|
+
} catch (e) {
|
|
83
|
+
pathModule = null;
|
|
84
|
+
}
|
|
85
|
+
modules.forEach((module2) => {
|
|
86
|
+
const fullPath = pathModule ? pathModule.resolve(module2) : module2;
|
|
87
|
+
rtmCtx.loadLibrary(fullPath);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return rtmCtx;
|
|
91
|
+
}
|
|
72
92
|
/**
|
|
73
93
|
* @param {RuntimeNameType} runtimeName
|
|
74
94
|
* @param {IConnectionData} connectionData
|
|
@@ -140,7 +160,10 @@ class RuntimeContext {
|
|
|
140
160
|
* @method
|
|
141
161
|
*/
|
|
142
162
|
async execute() {
|
|
143
|
-
|
|
163
|
+
if (!this.#currentCommand) {
|
|
164
|
+
throw new Error("currentCommand is undefined in Runtime Context execute method");
|
|
165
|
+
}
|
|
166
|
+
this.#responseCommand = await import_Interpreter.Interpreter.execute(this.#currentCommand, this.connectionData);
|
|
144
167
|
this.#currentCommand = null;
|
|
145
168
|
if (this.#responseCommand === void 0) {
|
|
146
169
|
throw new Error("responseCommand is undefined in Runtime Context execute method");
|
|
@@ -225,7 +248,7 @@ class RuntimeContext {
|
|
|
225
248
|
* After creating the reference, it can be used as an argument when invoking methods.
|
|
226
249
|
* @param {...any} args - The value and optionally the type of the reference.
|
|
227
250
|
* @returns {InvocationContext} InvocationContext instance that wraps the command to create a reference as out.
|
|
228
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/methods-arguments/passing-arguments-by-reference-with-out-keyword |Passing Arguments by Reference with out Keyword Guide)
|
|
251
|
+
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/methods-arguments/passing-arguments-by-reference-with-out-keyword |Passing Arguments by Reference with 'out' Keyword Guide)
|
|
229
252
|
* @method
|
|
230
253
|
*/
|
|
231
254
|
asOut(...args) {
|
|
@@ -234,7 +257,7 @@ class RuntimeContext {
|
|
|
234
257
|
return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
|
|
235
258
|
}
|
|
236
259
|
/**
|
|
237
|
-
* Retrieves the value of
|
|
260
|
+
* Retrieves the value of a global field from the target runtime.
|
|
238
261
|
* @param {string} fieldName - The name of the field to get.
|
|
239
262
|
* @returns {InvocationContext} A new InvocationContext instance that wraps the command to get the global field.
|
|
240
263
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/fields-and-properties/getting-values-for-global-fields)
|
|
@@ -308,11 +331,6 @@ class RuntimeContext {
|
|
|
308
331
|
);
|
|
309
332
|
}
|
|
310
333
|
}
|
|
311
|
-
healthCheck() {
|
|
312
|
-
let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.Value, ["health_check"]);
|
|
313
|
-
this.#currentCommand = this.#buildCommand(localCommand);
|
|
314
|
-
this.execute();
|
|
315
|
-
}
|
|
316
334
|
}
|
|
317
335
|
// Annotate the CommonJS export names for ESM import in node:
|
|
318
336
|
0 && (module.exports = {
|
|
@@ -23,7 +23,6 @@ __export(RuntimeFactory_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(RuntimeFactory_exports);
|
|
24
24
|
var import_RuntimeName = require("../utils/RuntimeName.cjs");
|
|
25
25
|
var import_RuntimeContext = require("./RuntimeContext.cjs");
|
|
26
|
-
var import_ConnectionType = require("../utils/ConnectionType.cjs");
|
|
27
26
|
class RuntimeFactory {
|
|
28
27
|
/**
|
|
29
28
|
* @param {IConnectionData} connectionData
|
|
@@ -103,27 +102,6 @@ class RuntimeFactory {
|
|
|
103
102
|
python27() {
|
|
104
103
|
return import_RuntimeContext.RuntimeContext.getInstance(import_RuntimeName.RuntimeName.Python27, this.connectionData);
|
|
105
104
|
}
|
|
106
|
-
/**
|
|
107
|
-
* @param {{ runtime: import("../types.js").RuntimeName; connectionData: import("../utils/connectionData/IConnectionData.js").IConnectionData; modules: string; }} config
|
|
108
|
-
*/
|
|
109
|
-
static initializeRuntimeContext(config) {
|
|
110
|
-
const rtmCtx = import_RuntimeContext.RuntimeContext.getInstance(config.runtime, config.connectionData);
|
|
111
|
-
if (config.connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
|
|
112
|
-
const modules = (config.modules || "").split(",").map((m) => m.trim()).filter((m) => m !== "");
|
|
113
|
-
let pathModule = null;
|
|
114
|
-
try {
|
|
115
|
-
const _require = typeof require !== "undefined" ? require : eval("require");
|
|
116
|
-
pathModule = _require("path");
|
|
117
|
-
} catch (e) {
|
|
118
|
-
pathModule = null;
|
|
119
|
-
}
|
|
120
|
-
modules.forEach((module2) => {
|
|
121
|
-
const fullPath = pathModule ? pathModule.resolve(module2) : module2;
|
|
122
|
-
rtmCtx.loadLibrary(fullPath);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return rtmCtx;
|
|
126
|
-
}
|
|
127
105
|
}
|
|
128
106
|
// Annotate the CommonJS export names for ESM import in node:
|
|
129
107
|
0 && (module.exports = {
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
export type RuntimeName = import("../../types.d.ts").RuntimeName;
|
|
2
2
|
export class Handler {
|
|
3
|
+
static _initialized: boolean;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {any} error
|
|
6
|
-
* @param {Command} command
|
|
7
|
-
* @returns {Command}
|
|
5
|
+
* Initializes the handlers map. This is called lazily on first use.
|
|
8
6
|
*/
|
|
9
|
-
static
|
|
7
|
+
static _initialize(): void;
|
|
10
8
|
/**
|
|
11
|
-
* @param {
|
|
9
|
+
* @param {Command} command
|
|
10
|
+
* @returns {Promise<Command> | Command}
|
|
12
11
|
*/
|
|
13
|
-
|
|
14
|
-
interpreter: import("../interpreter/Interpreter.js").Interpreter;
|
|
12
|
+
static handleCommand(command: Command): Promise<Command> | Command;
|
|
15
13
|
/**
|
|
14
|
+
* Prefer innerException (or cause) when available.
|
|
15
|
+
* @param {any} error
|
|
16
16
|
* @param {Command} command
|
|
17
|
-
* @returns {
|
|
17
|
+
* @returns {Command}
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
static resolveException(error: any, command: Command): Command;
|
|
20
20
|
/**
|
|
21
21
|
* @param {any} response
|
|
22
22
|
* @param {RuntimeName} runtimeName
|
|
23
23
|
* @returns {Promise<Command> | Command}
|
|
24
24
|
*/
|
|
25
|
-
parseCommand(response: any, runtimeName: RuntimeName): Promise<Command> | Command;
|
|
25
|
+
static parseCommand(response: any, runtimeName: RuntimeName): Promise<Command> | Command;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* @typedef {import('../../types.d.ts').RuntimeName} RuntimeName
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
export type Command = import("../../utils/Command.js").Command;
|
|
2
|
-
export type Interpreter = import("../interpreter/Interpreter.js").Interpreter;
|
|
3
2
|
/**
|
|
4
3
|
* @typedef {import('../../utils/Command.js').Command} Command
|
|
5
|
-
* @typedef {import('../interpreter/Interpreter.js').Interpreter} Interpreter
|
|
6
4
|
*/
|
|
7
5
|
/**
|
|
8
6
|
* PassDelegateHandler class responsible for processing a command to create a delegate.
|
|
9
7
|
*/
|
|
10
8
|
export class PassDelegateHandler extends AbstractHandler {
|
|
11
|
-
constructor(interpreter?: null);
|
|
12
|
-
/** @type {Interpreter | null | undefined} */
|
|
13
|
-
interpreter: Interpreter | null | undefined;
|
|
14
9
|
/**
|
|
15
10
|
* Minimum required parameters count for the command.
|
|
16
11
|
* @type {number}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
export class Interpreter {
|
|
2
|
-
/** @type {Handler | null} */
|
|
3
|
-
_handler: Handler | null;
|
|
4
|
-
/** @type {Handler} */
|
|
5
|
-
get handler(): Handler;
|
|
6
2
|
/**
|
|
7
3
|
*
|
|
8
4
|
* @param {Command} command
|
|
9
5
|
* @param {IConnectionData} connectionData
|
|
10
6
|
* @returns {Promise<Command>}
|
|
11
7
|
*/
|
|
12
|
-
execute(command: Command, connectionData: IConnectionData): Promise<Command>;
|
|
8
|
+
static execute(command: Command, connectionData: IConnectionData): Promise<Command>;
|
|
13
9
|
/**
|
|
14
10
|
*
|
|
15
11
|
* @param {Uint8Array} messageByteArray
|
|
16
12
|
* @returns {Promise<Command> | Command}
|
|
17
13
|
*/
|
|
18
|
-
process(messageByteArray: Uint8Array): Promise<Command> | Command;
|
|
14
|
+
static process(messageByteArray: Uint8Array): Promise<Command> | Command;
|
|
19
15
|
}
|
|
20
16
|
export type IConnectionData = import("../../utils/connectionData/IConnectionData.js").IConnectionData;
|
|
21
17
|
export type RuntimeNameType = typeof import("../../types.d.ts").RuntimeName;
|
|
22
18
|
export type Command = import("../../utils/Command.js").Command;
|
|
23
|
-
import { Handler } from '../handler/Handler.js';
|
|
@@ -10,12 +10,12 @@ export class CommandSerializer {
|
|
|
10
10
|
* @param {number} runtimeVersion
|
|
11
11
|
* @returns {Uint8Array}
|
|
12
12
|
*/
|
|
13
|
-
serialize(rootCommand: Command, connectionData: IConnectionData, runtimeVersion?: number): Uint8Array;
|
|
13
|
+
static serialize(rootCommand: Command, connectionData: IConnectionData, runtimeVersion?: number): Uint8Array;
|
|
14
14
|
/**
|
|
15
15
|
* Recursively serializes command payload.
|
|
16
16
|
* @param {Command} command
|
|
17
17
|
* @param {Array<Uint8Array>} buffers
|
|
18
18
|
*/
|
|
19
|
-
serializeRecursively(command: Command, buffers: Array<Uint8Array>): void;
|
|
19
|
+
static serializeRecursively(command: Command, buffers: Array<Uint8Array>): void;
|
|
20
20
|
}
|
|
21
21
|
import { Command } from '../../utils/Command.js';
|
|
@@ -72,6 +72,7 @@ export class Javonet {
|
|
|
72
72
|
*/
|
|
73
73
|
static initializeRc(configName: string): RuntimeContext;
|
|
74
74
|
}
|
|
75
|
+
import { RuntimeContext } from './RuntimeContext.js';
|
|
75
76
|
import { TcpConnectionData } from '../utils/nodejs/connectionData/TcpConnectionData.js';
|
|
76
77
|
import { WsConnectionData } from '../utils/connectionData/WsConnectionData.js';
|
|
77
78
|
import { CommandSerializer } from '../core/protocol/CommandSerializer.js';
|
|
@@ -80,5 +81,4 @@ import { ConfigPriority } from './configuration/ConfigPriority.js';
|
|
|
80
81
|
import { ComplexTypeResolver } from './tools/ComplexTypeResolver.js';
|
|
81
82
|
import { RuntimeFactory } from './RuntimeFactory.js';
|
|
82
83
|
import { ConfigRuntimeFactory } from './ConfigRuntimeFactory.js';
|
|
83
|
-
|
|
84
|
-
export { TcpConnectionData, WsConnectionData, CommandSerializer, CommandDeserializer, ConfigPriority, ComplexTypeResolver };
|
|
84
|
+
export { RuntimeContext, TcpConnectionData, WsConnectionData, CommandSerializer, CommandDeserializer, ConfigPriority, ComplexTypeResolver };
|
|
@@ -19,6 +19,11 @@ export class RuntimeContext {
|
|
|
19
19
|
static networkRuntimeContexts: Map<string, RuntimeContext>;
|
|
20
20
|
/** @type {Map<string, RuntimeContext>} */
|
|
21
21
|
static webSocketRuntimeContexts: Map<string, RuntimeContext>;
|
|
22
|
+
/**
|
|
23
|
+
* @param {Config} config
|
|
24
|
+
* @returns {RuntimeContext}
|
|
25
|
+
*/
|
|
26
|
+
static initializeRuntimeContext(config: Config): RuntimeContext;
|
|
22
27
|
/**
|
|
23
28
|
* @param {RuntimeNameType} runtimeName
|
|
24
29
|
* @param {IConnectionData} connectionData
|
|
@@ -99,12 +104,12 @@ export class RuntimeContext {
|
|
|
99
104
|
* After creating the reference, it can be used as an argument when invoking methods.
|
|
100
105
|
* @param {...any} args - The value and optionally the type of the reference.
|
|
101
106
|
* @returns {InvocationContext} InvocationContext instance that wraps the command to create a reference as out.
|
|
102
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/methods-arguments/passing-arguments-by-reference-with-out-keyword |Passing Arguments by Reference with out Keyword Guide)
|
|
107
|
+
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/methods-arguments/passing-arguments-by-reference-with-out-keyword |Passing Arguments by Reference with 'out' Keyword Guide)
|
|
103
108
|
* @method
|
|
104
109
|
*/
|
|
105
110
|
asOut(...args: any[]): InvocationContext;
|
|
106
111
|
/**
|
|
107
|
-
* Retrieves the value of
|
|
112
|
+
* Retrieves the value of a global field from the target runtime.
|
|
108
113
|
* @param {string} fieldName - The name of the field to get.
|
|
109
114
|
* @returns {InvocationContext} A new InvocationContext instance that wraps the command to get the global field.
|
|
110
115
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/fields-and-properties/getting-values-for-global-fields)
|
|
@@ -122,7 +127,7 @@ export class RuntimeContext {
|
|
|
122
127
|
* @method
|
|
123
128
|
*/
|
|
124
129
|
invokeGlobalFunction(functionName: string, ...args: any[]): InvocationContext;
|
|
125
|
-
healthCheck(): void;
|
|
126
130
|
#private;
|
|
127
131
|
}
|
|
128
132
|
import { InvocationContext } from './InvocationContext.js';
|
|
133
|
+
import { Config } from "./configuration/Config.js";
|
|
@@ -7,14 +7,6 @@
|
|
|
7
7
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
|
|
8
8
|
*/
|
|
9
9
|
export class RuntimeFactory {
|
|
10
|
-
/**
|
|
11
|
-
* @param {{ runtime: import("../types.js").RuntimeName; connectionData: import("../utils/connectionData/IConnectionData.js").IConnectionData; modules: string; }} config
|
|
12
|
-
*/
|
|
13
|
-
static initializeRuntimeContext(config: {
|
|
14
|
-
runtime: import("../types.js").RuntimeName;
|
|
15
|
-
connectionData: import("../utils/connectionData/IConnectionData.js").IConnectionData;
|
|
16
|
-
modules: string;
|
|
17
|
-
}): RuntimeContext;
|
|
18
10
|
/**
|
|
19
11
|
* @param {IConnectionData} connectionData
|
|
20
12
|
*/
|
|
@@ -119,31 +119,34 @@ const handlers = {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
class Handler {
|
|
122
|
+
static _initialized = false
|
|
123
|
+
|
|
122
124
|
/**
|
|
123
|
-
*
|
|
125
|
+
* Initializes the handlers map. This is called lazily on first use.
|
|
124
126
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (!this.interpreter) {
|
|
129
|
-
throw new Error('interpreter is undefined in Handler constructor')
|
|
127
|
+
static _initialize() {
|
|
128
|
+
if (Handler._initialized) {
|
|
129
|
+
return
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
// dynamically create pass delegate handler
|
|
133
|
-
|
|
134
|
-
handlers[CommandType.PassDelegate] = new PassDelegateHandler(this.interpreter)
|
|
132
|
+
// dynamically create pass delegate handler
|
|
133
|
+
handlers[CommandType.PassDelegate] = new PassDelegateHandler()
|
|
135
134
|
|
|
136
135
|
Object.keys(handlers).forEach((commandTypeHandler) => {
|
|
137
136
|
// @ts-expect-error
|
|
138
137
|
handlers[commandTypeHandler].handlers = handlers
|
|
139
138
|
})
|
|
139
|
+
|
|
140
|
+
Handler._initialized = true
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
/**
|
|
143
144
|
* @param {Command} command
|
|
144
145
|
* @returns {Promise<Command> | Command}
|
|
145
146
|
*/
|
|
146
|
-
handleCommand(command) {
|
|
147
|
+
static handleCommand(command) {
|
|
148
|
+
Handler._initialize()
|
|
149
|
+
|
|
147
150
|
try {
|
|
148
151
|
if (command.commandType === CommandType.RetrieveArray) {
|
|
149
152
|
/** @type {any} */
|
|
@@ -153,7 +156,7 @@ class Handler {
|
|
|
153
156
|
|
|
154
157
|
/** @type {any} */
|
|
155
158
|
const response = handlers[command.commandType].handleCommand(command)
|
|
156
|
-
return
|
|
159
|
+
return Handler.parseCommand(response, command.runtimeName)
|
|
157
160
|
} catch (e) {
|
|
158
161
|
return Handler.resolveException(e, command)
|
|
159
162
|
}
|
|
@@ -175,10 +178,10 @@ class Handler {
|
|
|
175
178
|
* @param {RuntimeName} runtimeName
|
|
176
179
|
* @returns {Promise<Command> | Command}
|
|
177
180
|
*/
|
|
178
|
-
parseCommand(response, runtimeName) {
|
|
181
|
+
static parseCommand(response, runtimeName) {
|
|
179
182
|
if (response instanceof Promise) {
|
|
180
183
|
return response.then((resolvedResponse) => {
|
|
181
|
-
return
|
|
184
|
+
return Handler.parseCommand(resolvedResponse, runtimeName)
|
|
182
185
|
})
|
|
183
186
|
}
|
|
184
187
|
|
|
@@ -6,24 +6,19 @@ import { AbstractHandler } from './AbstractHandler.js'
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {import('../../utils/Command.js').Command} Command
|
|
9
|
-
* @typedef {import('../interpreter/Interpreter.js').Interpreter} Interpreter
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* PassDelegateHandler class responsible for processing a command to create a delegate.
|
|
14
13
|
*/
|
|
15
14
|
class PassDelegateHandler extends AbstractHandler {
|
|
16
|
-
|
|
17
|
-
interpreter = null
|
|
18
|
-
|
|
19
|
-
constructor(interpreter = null) {
|
|
15
|
+
constructor() {
|
|
20
16
|
super()
|
|
21
17
|
/**
|
|
22
18
|
* Minimum required parameters count for the command.
|
|
23
19
|
* @type {number}
|
|
24
20
|
*/
|
|
25
21
|
this.requiredParametersCount = 1
|
|
26
|
-
this.interpreter = interpreter
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
/**S
|
|
@@ -116,7 +111,8 @@ class PassDelegateHandler extends AbstractHandler {
|
|
|
116
111
|
* @returns {Promise<any>} The response object.
|
|
117
112
|
*/
|
|
118
113
|
async createExecuteCall(command) {
|
|
119
|
-
|
|
114
|
+
const { Interpreter } = await import('../interpreter/Interpreter.js')
|
|
115
|
+
return Interpreter.execute(command, new InMemoryConnectionData())
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
/**
|
|
@@ -24,16 +24,6 @@ let _TransmitterWebsocket = isNodejsRuntime() ? TransmitterWebsocket : Transmitt
|
|
|
24
24
|
const requireDynamic = getRequire(import.meta.url)
|
|
25
25
|
|
|
26
26
|
export class Interpreter {
|
|
27
|
-
/** @type {Handler | null} */
|
|
28
|
-
_handler = null
|
|
29
|
-
|
|
30
|
-
/** @type {Handler} */
|
|
31
|
-
get handler() {
|
|
32
|
-
if (!this._handler) {
|
|
33
|
-
this._handler = new Handler(this)
|
|
34
|
-
}
|
|
35
|
-
return this._handler
|
|
36
|
-
}
|
|
37
27
|
|
|
38
28
|
/**
|
|
39
29
|
*
|
|
@@ -41,9 +31,9 @@ export class Interpreter {
|
|
|
41
31
|
* @param {IConnectionData} connectionData
|
|
42
32
|
* @returns {Promise<Command>}
|
|
43
33
|
*/
|
|
44
|
-
async execute(command, connectionData) {
|
|
34
|
+
static async execute(command, connectionData) {
|
|
45
35
|
try {
|
|
46
|
-
let messageByteArray =
|
|
36
|
+
let messageByteArray = CommandSerializer.serialize(command, connectionData)
|
|
47
37
|
|
|
48
38
|
if (!(messageByteArray instanceof Uint8Array)) {
|
|
49
39
|
throw new Error('Serialized message is not Uint8Array')
|
|
@@ -100,10 +90,10 @@ export class Interpreter {
|
|
|
100
90
|
* @param {Uint8Array} messageByteArray
|
|
101
91
|
* @returns {Promise<Command> | Command}
|
|
102
92
|
*/
|
|
103
|
-
process(messageByteArray) {
|
|
93
|
+
static process(messageByteArray) {
|
|
104
94
|
try {
|
|
105
95
|
const receivedCommand = new CommandDeserializer(messageByteArray).deserialize()
|
|
106
|
-
return
|
|
96
|
+
return Handler.handleCommand(receivedCommand)
|
|
107
97
|
} catch (error) {
|
|
108
98
|
throw error
|
|
109
99
|
}
|
|
@@ -55,7 +55,7 @@ export class CommandDeserializer {
|
|
|
55
55
|
case 'JAVONET_DOUBLE':
|
|
56
56
|
return this.readDouble()
|
|
57
57
|
case 'JAVONET_UNSIGNED_LONG_LONG':
|
|
58
|
-
return this.readUllong
|
|
58
|
+
return this.readUllong()
|
|
59
59
|
case 'JAVONET_UNSIGNED_INTEGER':
|
|
60
60
|
return this.readUInt()
|
|
61
61
|
case 'JAVONET_NULL':
|
|
@@ -17,7 +17,7 @@ class CommandSerializer {
|
|
|
17
17
|
* @param {number} runtimeVersion
|
|
18
18
|
* @returns {Uint8Array}
|
|
19
19
|
*/
|
|
20
|
-
serialize(rootCommand, connectionData, runtimeVersion = 0) {
|
|
20
|
+
static serialize(rootCommand, connectionData, runtimeVersion = 0) {
|
|
21
21
|
/** @type {Array<Uint8Array>} */
|
|
22
22
|
const buffers = []
|
|
23
23
|
|
|
@@ -34,7 +34,7 @@ class CommandSerializer {
|
|
|
34
34
|
buffers.push(Uint8Array.of(RuntimeName.Python, rootCommand.commandType))
|
|
35
35
|
|
|
36
36
|
// Recursively serialize command and its payload
|
|
37
|
-
|
|
37
|
+
CommandSerializer.serializeRecursively(rootCommand, buffers)
|
|
38
38
|
|
|
39
39
|
return concatenateUint8Arrays(buffers)
|
|
40
40
|
}
|
|
@@ -44,18 +44,18 @@ class CommandSerializer {
|
|
|
44
44
|
* @param {Command} command
|
|
45
45
|
* @param {Array<Uint8Array>} buffers
|
|
46
46
|
*/
|
|
47
|
-
serializeRecursively(command, buffers) {
|
|
47
|
+
static serializeRecursively(command, buffers) {
|
|
48
48
|
for (const item of command.payload) {
|
|
49
49
|
if (item instanceof Command) {
|
|
50
50
|
buffers.push(TypeSerializer.serializeCommand(item))
|
|
51
|
-
|
|
51
|
+
CommandSerializer.serializeRecursively(item, buffers)
|
|
52
52
|
} else if (TypesHandler.isPrimitiveOrNullOrUndefined(item)) {
|
|
53
53
|
buffers.push(TypeSerializer.serializePrimitive(item))
|
|
54
54
|
} else {
|
|
55
55
|
const cachedReference = ReferencesCache.getInstance().cacheReference(item)
|
|
56
56
|
const refCommand = new Command(RuntimeName.Nodejs, CommandType.Reference, cachedReference)
|
|
57
57
|
buffers.push(TypeSerializer.serializeCommand(refCommand))
|
|
58
|
-
|
|
58
|
+
CommandSerializer.serializeRecursively(refCommand, buffers)
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import { Interpreter } from '../interpreter/Interpreter.js'
|
|
3
2
|
import { CommandSerializer } from '../protocol/CommandSerializer.js'
|
|
4
|
-
import { getRequire } from '../../utils/Runtime.js'
|
|
5
3
|
import { InMemoryConnectionData } from '../../utils/connectionData/InMemoryConnectionData.js'
|
|
6
4
|
import { ExceptionSerializer } from '../../utils/exception/ExceptionSerializer.js'
|
|
7
5
|
import { Command } from '../../utils/Command.js'
|
|
8
6
|
import { CommandType } from '../../utils/CommandType.js'
|
|
9
7
|
import { RuntimeName } from '../../utils/RuntimeName.js'
|
|
10
8
|
import { RuntimeLogger } from '../../utils/RuntimeLogger.js'
|
|
9
|
+
import { Interpreter } from './../interpreter/Interpreter.js'
|
|
11
10
|
|
|
12
11
|
export class Receiver {
|
|
13
12
|
static connectionData = new InMemoryConnectionData()
|
|
14
|
-
Receiver() {}
|
|
15
13
|
|
|
16
14
|
static getRuntimeInfo() {
|
|
17
15
|
return RuntimeLogger.getRuntimeInfo()
|
|
@@ -23,14 +21,14 @@ export class Receiver {
|
|
|
23
21
|
*/
|
|
24
22
|
static async sendCommand(messageByteArray) {
|
|
25
23
|
try {
|
|
26
|
-
let command = await
|
|
27
|
-
return
|
|
24
|
+
let command = await Interpreter.process(messageByteArray)
|
|
25
|
+
return CommandSerializer.serialize(command, this.connectionData)
|
|
28
26
|
} catch (error) {
|
|
29
27
|
const exceptionCommand = ExceptionSerializer.serializeException(
|
|
30
28
|
error,
|
|
31
29
|
new Command(RuntimeName.Nodejs, CommandType.Exception, [])
|
|
32
30
|
)
|
|
33
|
-
return
|
|
31
|
+
return CommandSerializer.serialize(exceptionCommand, this.connectionData)
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
|
|
@@ -50,8 +50,6 @@ class InvocationContext {
|
|
|
50
50
|
#responseCommand = null
|
|
51
51
|
/** @type {boolean} */
|
|
52
52
|
#isExecuted = false
|
|
53
|
-
/** @type {Interpreter | null} */
|
|
54
|
-
#interpreter = null
|
|
55
53
|
/** @type {string | null} */
|
|
56
54
|
#guid = null
|
|
57
55
|
/** @type {AsyncLock} */
|
|
@@ -60,6 +58,8 @@ class InvocationContext {
|
|
|
60
58
|
// Static map holding contexts waiting for materialization (guid -> InvocationContext)
|
|
61
59
|
static _invocationContexts = new Map()
|
|
62
60
|
|
|
61
|
+
//
|
|
62
|
+
|
|
63
63
|
/**
|
|
64
64
|
*
|
|
65
65
|
* @param {RuntimeNameType} runtimeName
|
|
@@ -73,7 +73,6 @@ class InvocationContext {
|
|
|
73
73
|
this.#currentCommand = command
|
|
74
74
|
this.#responseCommand = null
|
|
75
75
|
this.#isExecuted = isExecuted
|
|
76
|
-
this.#interpreter = null
|
|
77
76
|
this.#guid = uuidv4()
|
|
78
77
|
}
|
|
79
78
|
|
|
@@ -142,11 +141,7 @@ class InvocationContext {
|
|
|
142
141
|
if (this.#currentCommand === null) {
|
|
143
142
|
throw new Error('currentCommand is undefined in Invocation Context execute method')
|
|
144
143
|
}
|
|
145
|
-
if (!this.#interpreter) {
|
|
146
|
-
this.#interpreter = new Interpreter()
|
|
147
|
-
}
|
|
148
144
|
|
|
149
|
-
// Zablokuj wszystkie konteksty do materializacji w deterministycznej kolejności (po GUID)
|
|
150
145
|
const entries = Array.from(InvocationContext._invocationContexts.entries())
|
|
151
146
|
entries.sort((a, b) => String(a[0]).localeCompare(String(b[0])))
|
|
152
147
|
const releases = []
|
|
@@ -158,7 +153,11 @@ class InvocationContext {
|
|
|
158
153
|
|
|
159
154
|
try {
|
|
160
155
|
// Execute command on interpreter
|
|
161
|
-
this.#responseCommand = await
|
|
156
|
+
this.#responseCommand = await Interpreter.execute(
|
|
157
|
+
this.#currentCommand,
|
|
158
|
+
this.#connectionData
|
|
159
|
+
)
|
|
160
|
+
|
|
162
161
|
|
|
163
162
|
if (!this.#responseCommand) {
|
|
164
163
|
throw new Error('responseCommand is undefined in Invocation Context execute method')
|
package/lib/sdk/Javonet.js
CHANGED
|
@@ -122,12 +122,13 @@ class Javonet {
|
|
|
122
122
|
*/
|
|
123
123
|
static initializeRc(configName) {
|
|
124
124
|
const config = ConfigSourceResolver.getConfig(configName)
|
|
125
|
-
return
|
|
125
|
+
return RuntimeContext.initializeRuntimeContext(config)
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
export {
|
|
130
130
|
Javonet,
|
|
131
|
+
RuntimeContext,
|
|
131
132
|
TcpConnectionData,
|
|
132
133
|
WsConnectionData,
|
|
133
134
|
CommandSerializer,
|
|
@@ -9,8 +9,10 @@ import { Interpreter } from '../core/interpreter/Interpreter.js'
|
|
|
9
9
|
import { delegatesCacheInstance } from '../core/delegatesCache/DelegatesCache.js'
|
|
10
10
|
import { TypesHandler } from '../utils/TypesHandler.js'
|
|
11
11
|
import { UtilsConst } from '../utils/UtilsConst.js'
|
|
12
|
+
import { Config } from "./configuration/Config.js"
|
|
12
13
|
import { getRequire, isNodejsRuntime } from '../utils/Runtime.js'
|
|
13
14
|
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* @typedef {import('../types.d.ts').RuntimeName} RuntimeNameType
|
|
16
18
|
* @typedef {import('../utils/connectionData/IConnectionData.js').IConnectionData} IConnectionData
|
|
@@ -45,8 +47,6 @@ class RuntimeContext {
|
|
|
45
47
|
#currentCommand = null
|
|
46
48
|
/** @type {Command | null} */
|
|
47
49
|
#responseCommand = null
|
|
48
|
-
/** @type {Interpreter | null} */
|
|
49
|
-
#interpreter = null
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* @param {RuntimeNameType} runtimeName
|
|
@@ -56,7 +56,6 @@ class RuntimeContext {
|
|
|
56
56
|
this._isExecuted = false
|
|
57
57
|
this.runtimeName = runtimeName
|
|
58
58
|
this.connectionData = connectionData
|
|
59
|
-
this.#interpreter = new Interpreter()
|
|
60
59
|
|
|
61
60
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
62
61
|
return
|
|
@@ -75,6 +74,40 @@ class RuntimeContext {
|
|
|
75
74
|
_Transmitter?.activate(UtilsConst.getLicenseKey())
|
|
76
75
|
}
|
|
77
76
|
|
|
77
|
+
/**
|
|
78
|
+
* @param {Config} config
|
|
79
|
+
* @returns {RuntimeContext}
|
|
80
|
+
*/
|
|
81
|
+
static initializeRuntimeContext(config) {
|
|
82
|
+
const rtmCtx = RuntimeContext.getInstance(config.runtime, config.connectionData)
|
|
83
|
+
|
|
84
|
+
if (config.connectionData.connectionType === ConnectionType.IN_MEMORY) {
|
|
85
|
+
const modules = (config.modules || '')
|
|
86
|
+
.split(',')
|
|
87
|
+
.map((m) => m.trim())
|
|
88
|
+
.filter((m) => m !== '')
|
|
89
|
+
|
|
90
|
+
// try to get Node's path module; if unavailable, fall back to simple checks
|
|
91
|
+
let pathModule = null
|
|
92
|
+
try {
|
|
93
|
+
// eslint-disable-next-line no-eval
|
|
94
|
+
const _require = typeof require !== 'undefined' ? require : eval('require')
|
|
95
|
+
pathModule = _require('path')
|
|
96
|
+
} catch (e) {
|
|
97
|
+
pathModule = null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
modules.forEach((module) => {
|
|
101
|
+
const fullPath = pathModule
|
|
102
|
+
? pathModule.resolve(module)
|
|
103
|
+
: module
|
|
104
|
+
rtmCtx.loadLibrary(fullPath)
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return rtmCtx
|
|
109
|
+
}
|
|
110
|
+
|
|
78
111
|
/**
|
|
79
112
|
* @param {RuntimeNameType} runtimeName
|
|
80
113
|
* @param {IConnectionData} connectionData
|
|
@@ -148,8 +181,10 @@ class RuntimeContext {
|
|
|
148
181
|
* @method
|
|
149
182
|
*/
|
|
150
183
|
async execute() {
|
|
151
|
-
|
|
152
|
-
|
|
184
|
+
if (!this.#currentCommand) {
|
|
185
|
+
throw new Error('currentCommand is undefined in Runtime Context execute method')
|
|
186
|
+
}
|
|
187
|
+
this.#responseCommand = await Interpreter.execute(this.#currentCommand, this.connectionData)
|
|
153
188
|
this.#currentCommand = null
|
|
154
189
|
if (this.#responseCommand === undefined) {
|
|
155
190
|
throw new Error('responseCommand is undefined in Runtime Context execute method')
|
|
@@ -240,7 +275,7 @@ class RuntimeContext {
|
|
|
240
275
|
* After creating the reference, it can be used as an argument when invoking methods.
|
|
241
276
|
* @param {...any} args - The value and optionally the type of the reference.
|
|
242
277
|
* @returns {InvocationContext} InvocationContext instance that wraps the command to create a reference as out.
|
|
243
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/methods-arguments/passing-arguments-by-reference-with-out-keyword |Passing Arguments by Reference with out Keyword Guide)
|
|
278
|
+
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/methods-arguments/passing-arguments-by-reference-with-out-keyword |Passing Arguments by Reference with 'out' Keyword Guide)
|
|
244
279
|
* @method
|
|
245
280
|
*/
|
|
246
281
|
asOut(...args) {
|
|
@@ -250,7 +285,7 @@ class RuntimeContext {
|
|
|
250
285
|
}
|
|
251
286
|
|
|
252
287
|
/**
|
|
253
|
-
* Retrieves the value of
|
|
288
|
+
* Retrieves the value of a global field from the target runtime.
|
|
254
289
|
* @param {string} fieldName - The name of the field to get.
|
|
255
290
|
* @returns {InvocationContext} A new InvocationContext instance that wraps the command to get the global field.
|
|
256
291
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/fields-and-properties/getting-values-for-global-fields)
|
|
@@ -331,12 +366,6 @@ class RuntimeContext {
|
|
|
331
366
|
)
|
|
332
367
|
}
|
|
333
368
|
}
|
|
334
|
-
|
|
335
|
-
healthCheck() {
|
|
336
|
-
let localCommand = new Command(this.runtimeName, CommandType.Value, ['health_check'])
|
|
337
|
-
this.#currentCommand = this.#buildCommand(localCommand)
|
|
338
|
-
this.execute()
|
|
339
|
-
}
|
|
340
369
|
}
|
|
341
370
|
|
|
342
371
|
export { RuntimeContext }
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//@ts-check
|
|
2
2
|
import { RuntimeName } from '../utils/RuntimeName.js'
|
|
3
3
|
import { RuntimeContext } from './RuntimeContext.js'
|
|
4
|
-
import { ConnectionType } from '../utils/ConnectionType.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @typedef {import('../utils/connectionData/IConnectionData.js').IConnectionData} IConnectionData
|
|
@@ -99,37 +98,4 @@ export class RuntimeFactory {
|
|
|
99
98
|
python27() {
|
|
100
99
|
return RuntimeContext.getInstance(RuntimeName.Python27, this.connectionData)
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @param {{ runtime: import("../types.js").RuntimeName; connectionData: import("../utils/connectionData/IConnectionData.js").IConnectionData; modules: string; }} config
|
|
105
|
-
*/
|
|
106
|
-
static initializeRuntimeContext(config) {
|
|
107
|
-
const rtmCtx = RuntimeContext.getInstance(config.runtime, config.connectionData)
|
|
108
|
-
|
|
109
|
-
if (config.connectionData.connectionType === ConnectionType.IN_MEMORY) {
|
|
110
|
-
const modules = (config.modules || '')
|
|
111
|
-
.split(',')
|
|
112
|
-
.map((m) => m.trim())
|
|
113
|
-
.filter((m) => m !== '')
|
|
114
|
-
|
|
115
|
-
// try to get Node's path module; if unavailable, fall back to simple checks
|
|
116
|
-
let pathModule = null
|
|
117
|
-
try {
|
|
118
|
-
// eslint-disable-next-line no-eval
|
|
119
|
-
const _require = typeof require !== 'undefined' ? require : eval('require')
|
|
120
|
-
pathModule = _require('path')
|
|
121
|
-
} catch (e) {
|
|
122
|
-
pathModule = null
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
modules.forEach((module) => {
|
|
126
|
-
const fullPath = pathModule
|
|
127
|
-
? pathModule.resolve(module)
|
|
128
|
-
: module
|
|
129
|
-
rtmCtx.loadLibrary(fullPath)
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return rtmCtx
|
|
134
|
-
}
|
|
135
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "javonet-nodejs-sdk",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.11",
|
|
4
4
|
"description": "Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology. It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products. Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today! For more information check out our guides at https://www.javonet.com/guides/v2/",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "SdNCenter Sp. z o. o.",
|