javonet-nodejs-sdk 2.6.4 → 2.6.5

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.
Files changed (49) hide show
  1. package/dist/core/handler/Handler.cjs +15 -4
  2. package/dist/core/handler/LoadLibraryHandler.cjs +10 -6
  3. package/dist/core/interpreter/Interpreter.cjs +42 -16
  4. package/dist/core/protocol/CommandDeserializer.cjs +4 -4
  5. package/dist/core/protocol/CommandSerializer.cjs +7 -2
  6. package/dist/core/protocol/TypeDeserializer.cjs +11 -11
  7. package/dist/core/receiver/Receiver.cjs +7 -8
  8. package/dist/core/receiver/ReceiverNative.cjs +4 -2
  9. package/dist/core/transmitter/Transmitter.cjs +2 -2
  10. package/dist/core/transmitter/TransmitterWebsocket.cjs +2 -2
  11. package/dist/core/transmitter/TransmitterWebsocketBrowser.cjs +2 -2
  12. package/dist/core/transmitter/TransmitterWrapper.cjs +2 -1
  13. package/dist/core/webSocketClient/WebSocketClient.cjs +4 -4
  14. package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +7 -7
  15. package/dist/sdk/InvocationContext.cjs +47 -38
  16. package/dist/sdk/tools/ComplexTypeResolver.cjs +28 -3
  17. package/dist/types/core/handler/Handler.d.ts +3 -3
  18. package/dist/types/core/interpreter/Interpreter.d.ts +3 -3
  19. package/dist/types/core/protocol/CommandDeserializer.d.ts +3 -3
  20. package/dist/types/core/protocol/CommandSerializer.d.ts +3 -3
  21. package/dist/types/core/protocol/TypeDeserializer.d.ts +22 -22
  22. package/dist/types/core/receiver/Receiver.d.ts +6 -5
  23. package/dist/types/core/receiver/ReceiverNative.d.ts +6 -4
  24. package/dist/types/core/transmitter/Transmitter.d.ts +3 -3
  25. package/dist/types/core/transmitter/TransmitterWebsocket.d.ts +3 -3
  26. package/dist/types/core/transmitter/TransmitterWebsocketBrowser.d.ts +3 -3
  27. package/dist/types/core/transmitter/TransmitterWrapper.d.ts +3 -2
  28. package/dist/types/core/webSocketClient/WebSocketClient.d.ts +7 -7
  29. package/dist/types/core/webSocketClient/WebSocketClientBrowser.d.ts +9 -9
  30. package/dist/types/sdk/InvocationContext.d.ts +7 -11
  31. package/dist/types/sdk/tools/ComplexTypeResolver.d.ts +2 -2
  32. package/lib/core/handler/Handler.js +18 -4
  33. package/lib/core/handler/LoadLibraryHandler.js +15 -7
  34. package/lib/core/interpreter/Interpreter.js +47 -20
  35. package/lib/core/protocol/CommandDeserializer.js +4 -4
  36. package/lib/core/protocol/CommandSerializer.js +8 -2
  37. package/lib/core/protocol/TypeDeserializer.js +11 -11
  38. package/lib/core/receiver/Receiver.js +7 -8
  39. package/lib/core/receiver/ReceiverNative.js +4 -2
  40. package/lib/core/transmitter/Transmitter.js +2 -2
  41. package/lib/core/transmitter/TransmitterWebsocket.js +2 -2
  42. package/lib/core/transmitter/TransmitterWebsocketBrowser.js +2 -2
  43. package/lib/core/transmitter/TransmitterWrapper.js +2 -1
  44. package/lib/core/webSocketClient/WebSocketClient.js +5 -5
  45. package/lib/core/webSocketClient/WebSocketClientBrowser.js +8 -8
  46. package/lib/sdk/InvocationContext.js +48 -41
  47. package/lib/sdk/RuntimeContext.js +0 -7
  48. package/lib/sdk/tools/ComplexTypeResolver.js +22 -3
  49. package/package.json +4 -2
@@ -146,10 +146,16 @@ class Handler {
146
146
  handleCommand(command) {
147
147
  try {
148
148
  if (command.commandType === import_CommandType.CommandType.RetrieveArray) {
149
- let responseArray = handlers[import_CommandType.CommandType.Reference].handleCommand(command.payload[0]);
150
- return import_Command.Command.createArrayResponse(responseArray, command.runtimeName);
149
+ const responseArray = handlers[import_CommandType.CommandType.Reference].handleCommand(command.payload[0]);
150
+ if (responseArray instanceof Promise) {
151
+ return responseArray.then((resolvedResponseArray) => {
152
+ return import_Command.Command.createArrayResponse(resolvedResponseArray, command.runtimeName);
153
+ });
154
+ } else {
155
+ return import_Command.Command.createArrayResponse(responseArray, command.runtimeName);
156
+ }
151
157
  }
152
- let response = handlers[command.commandType].handleCommand(command);
158
+ const response = handlers[command.commandType].handleCommand(command);
153
159
  return this.parseCommand(response, command.runtimeName);
154
160
  } catch (e) {
155
161
  return import_ExceptionSerializer.ExceptionSerializer.serializeException(e, command);
@@ -158,9 +164,14 @@ class Handler {
158
164
  /**
159
165
  * @param {any} response
160
166
  * @param {RuntimeName} runtimeName
161
- * @returns {Command}
167
+ * @returns {Promise<Command> | Command}
162
168
  */
163
169
  parseCommand(response, runtimeName) {
170
+ if (response instanceof Promise) {
171
+ return response.then((resolvedResponse) => {
172
+ return this.parseCommand(resolvedResponse, runtimeName);
173
+ });
174
+ }
164
175
  if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(response)) {
165
176
  return import_Command.Command.createResponse(response, runtimeName);
166
177
  } else {
@@ -23,6 +23,8 @@ __export(LoadLibraryHandler_exports, {
23
23
  module.exports = __toCommonJS(LoadLibraryHandler_exports);
24
24
  var import_Runtime = require("../../utils/Runtime.cjs");
25
25
  var import_AbstractHandler = require("./AbstractHandler.cjs");
26
+ var import_fs = require("fs");
27
+ var import_path = require("path");
26
28
  const import_meta = {};
27
29
  const dynamicImport = (0, import_Runtime.getRequire)(import_meta.url);
28
30
  class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
@@ -41,6 +43,13 @@ class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
41
43
  }
42
44
  let { payload } = command;
43
45
  let [lib] = payload;
46
+ if (!lib) {
47
+ throw new Error("Cannot load module: Library path is required but was not provided");
48
+ }
49
+ const absolutePath = (0, import_path.resolve)(lib);
50
+ if (!(0, import_fs.existsSync)(lib) && !(0, import_fs.existsSync)(absolutePath)) {
51
+ throw new Error(`Cannot load module: Library not found: ${lib}`);
52
+ }
44
53
  let pathArray = lib.split(/[/\\]/);
45
54
  let libraryName = pathArray.length > 1 ? pathArray[pathArray.length - 1] : pathArray[0];
46
55
  libraryName = libraryName.replace(".js", "");
@@ -49,12 +58,7 @@ class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
49
58
  moduleExports = dynamicImport(lib);
50
59
  LoadLibraryHandler.loadedLibraries.push(lib);
51
60
  } catch (error) {
52
- try {
53
- const modulePath = `${process.cwd()}/${lib}`;
54
- moduleExports = dynamicImport(modulePath);
55
- } catch (error2) {
56
- throw this.process_stack_trace(error2, this.constructor.name);
57
- }
61
+ throw Error("Cannot load module: " + lib + "\n" + error);
58
62
  }
59
63
  global[libraryName] = moduleExports;
60
64
  for (const [key, value] of Object.entries(moduleExports)) {
@@ -30,8 +30,8 @@ var import_TransmitterWebsocketBrowser = require("../transmitter/TransmitterWebs
30
30
  var import_TransmitterWebsocket = require("../transmitter/TransmitterWebsocket.cjs");
31
31
  var import_Handler = require("../handler/Handler.cjs");
32
32
  const import_meta = {};
33
- let _Receiver = null;
34
- let _Transmitter = null;
33
+ let _Receiver;
34
+ let _Transmitter;
35
35
  let _TransmitterWebsocket = null;
36
36
  if (!_TransmitterWebsocket) {
37
37
  _TransmitterWebsocket = (0, import_Runtime.isNodejsRuntime)() ? import_TransmitterWebsocket.TransmitterWebsocket : import_TransmitterWebsocketBrowser.TransmitterWebsocketBrowser;
@@ -58,7 +58,10 @@ class Interpreter {
58
58
  let messageByteArray = new import_CommandSerializer.CommandSerializer().serialize(command, connectionData);
59
59
  let responseByteArray = void 0;
60
60
  if (connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
61
- const _response = await _TransmitterWebsocket?.sendCommand(messageByteArray, connectionData);
61
+ const _response = await _TransmitterWebsocket?.sendCommand(
62
+ await messageByteArray,
63
+ connectionData
64
+ );
62
65
  if (_response) {
63
66
  const command2 = new import_CommandDeserializer.CommandDeserializer(_response).deserialize();
64
67
  return command2;
@@ -74,13 +77,13 @@ class Interpreter {
74
77
  const { Receiver } = require("../receiver/Receiver.cjs");
75
78
  _Receiver = Receiver;
76
79
  }
77
- responseByteArray = await _Receiver?.sendCommand(messageByteArray);
80
+ responseByteArray = await _Receiver?.sendCommand(await messageByteArray);
78
81
  } else {
79
82
  if (!_Transmitter) {
80
83
  const { Transmitter } = require("../transmitter/Transmitter.cjs");
81
84
  _Transmitter = Transmitter;
82
85
  }
83
- responseByteArray = await _Transmitter?.sendCommand(messageByteArray);
86
+ responseByteArray = await _Transmitter?.sendCommand(await messageByteArray);
84
87
  }
85
88
  }
86
89
  if (!responseByteArray) {
@@ -103,37 +106,60 @@ class Interpreter {
103
106
  let responseByteArray = void 0;
104
107
  if (connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
105
108
  throw new Error("Not supported");
106
- }
107
- if (connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
109
+ } else {
108
110
  if (!(0, import_Runtime.isNodejsRuntime)()) {
109
111
  throw new Error("InMemory is only allowed in Nodejs runtime");
110
112
  }
111
- if (command.runtimeName === import_RuntimeName.RuntimeName.Nodejs) {
113
+ if (command.runtimeName === import_RuntimeName.RuntimeName.Nodejs && connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
112
114
  if (!_Receiver) {
113
115
  const { Receiver } = require("../receiver/Receiver.cjs");
114
116
  _Receiver = Receiver;
115
117
  }
116
- responseByteArray = _Receiver?.sendCommand(messageByteArray);
118
+ if (!_Receiver) {
119
+ throw new Error("Receiver is undefined");
120
+ }
121
+ if (messageByteArray instanceof Uint8Array) {
122
+ responseByteArray = _Receiver.sendCommand(messageByteArray);
123
+ } else {
124
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
125
+ return _Receiver.sendCommand(resolvedMessage);
126
+ });
127
+ }
117
128
  } else {
118
129
  if (!_Transmitter) {
119
130
  const { Transmitter } = require("../transmitter/Transmitter.cjs");
120
131
  _Transmitter = Transmitter;
121
132
  }
122
- responseByteArray = _Transmitter?.sendCommand(messageByteArray);
133
+ if (!_Transmitter) {
134
+ throw new Error("Transmitter is undefined");
135
+ }
136
+ if (messageByteArray instanceof Uint8Array) {
137
+ responseByteArray = _Transmitter.sendCommand(messageByteArray);
138
+ } else {
139
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
140
+ return _Transmitter.sendCommand(resolvedMessage);
141
+ });
142
+ }
143
+ }
144
+ if (!responseByteArray) {
145
+ throw new Error("No response received from Transmitter");
146
+ }
147
+ if (responseByteArray instanceof Promise) {
148
+ return responseByteArray.then((resolvedResponse) => {
149
+ return new import_CommandDeserializer.CommandDeserializer(resolvedResponse).deserialize();
150
+ });
151
+ } else {
152
+ return new import_CommandDeserializer.CommandDeserializer(responseByteArray).deserialize();
123
153
  }
124
154
  }
125
- if (!responseByteArray) {
126
- throw new Error("No response received from Transmitter");
127
- }
128
- return new import_CommandDeserializer.CommandDeserializer(responseByteArray).deserialize();
129
155
  } catch (error) {
130
156
  throw error;
131
157
  }
132
158
  }
133
159
  /**
134
160
  *
135
- * @param {Int8Array} messageByteArray
136
- * @returns {Command}
161
+ * @param {Uint8Array} messageByteArray
162
+ * @returns {Promise<Command> | Command}
137
163
  */
138
164
  process(messageByteArray) {
139
165
  try {
@@ -26,11 +26,11 @@ var import_Type = require("../../utils/Type.cjs");
26
26
  var import_TypeDeserializer = require("./TypeDeserializer.cjs");
27
27
  class CommandDeserializer {
28
28
  /**
29
- * @param {Int8Array} buffer
29
+ * @param {Uint8Array} byteArray
30
30
  */
31
- constructor(buffer) {
32
- this.buffer = buffer;
33
- this.command = new import_Command.Command(buffer[0], buffer[10], []);
31
+ constructor(byteArray) {
32
+ this.buffer = byteArray;
33
+ this.command = new import_Command.Command(this.buffer[0], this.buffer[10], []);
34
34
  this.position = 11;
35
35
  }
36
36
  /**
@@ -30,13 +30,18 @@ var import_TypesHandler = require("../../utils/TypesHandler.cjs");
30
30
  class CommandSerializer {
31
31
  /**
32
32
  * Serializes the root command with connection data and optional runtime version.
33
- * @param {Command} rootCommand
33
+ * @param {Promise<Command> | Command} rootCommand
34
34
  * @param {IConnectionData} connectionData
35
35
  * @param {number} runtimeVersion
36
- * @returns {Int8Array}
36
+ * @returns {Promise<Uint8Array> | Uint8Array}
37
37
  */
38
38
  serialize(rootCommand, connectionData, runtimeVersion = 0) {
39
39
  const buffers = [];
40
+ if (rootCommand instanceof Promise) {
41
+ return rootCommand.then((resolvedCommand) => {
42
+ return this.serialize(resolvedCommand, connectionData, runtimeVersion);
43
+ });
44
+ }
40
45
  buffers.push(Uint8Array.of(rootCommand.runtimeName, runtimeVersion));
41
46
  if (connectionData) {
42
47
  buffers.push(connectionData.serializeConnectionData());
@@ -26,7 +26,7 @@ var import_buffer = require("buffer");
26
26
  var import_StringEncodingMode = require("../../utils/StringEncodingMode.cjs");
27
27
  class TypeDeserializer {
28
28
  /**
29
- * @param {Int8Array} encodedCommand
29
+ * @param {Uint8Array} encodedCommand
30
30
  * @returns {Command}
31
31
  */
32
32
  static deserializeCommand(encodedCommand) {
@@ -34,7 +34,7 @@ class TypeDeserializer {
34
34
  }
35
35
  /**
36
36
  * @param {number} stringEncodingMode
37
- * @param {Int8Array} encodedString
37
+ * @param {Uint8Array} encodedString
38
38
  */
39
39
  static deserializeString(stringEncodingMode, encodedString) {
40
40
  switch (stringEncodingMode) {
@@ -62,55 +62,55 @@ class TypeDeserializer {
62
62
  }
63
63
  }
64
64
  /**
65
- * @param {Int8Array} encodedInt
65
+ * @param {Uint8Array} encodedInt
66
66
  */
67
67
  static deserializeInt(encodedInt) {
68
68
  return encodedInt[0] & 255 | (encodedInt[1] & 255) << 8 | (encodedInt[2] & 255) << 16 | (encodedInt[3] & 255) << 24;
69
69
  }
70
70
  /**
71
- * @param {Int8Array} encodedBool
71
+ * @param {Uint8Array} encodedBool
72
72
  */
73
73
  static deserializeBool(encodedBool) {
74
74
  return encodedBool[0] === 1;
75
75
  }
76
76
  /**
77
- * @param {Int8Array} encodedFloat
77
+ * @param {Uint8Array} encodedFloat
78
78
  */
79
79
  static deserializeFloat(encodedFloat) {
80
80
  return import_buffer.Buffer.from(encodedFloat).readFloatLE();
81
81
  }
82
82
  /**
83
- * @param {Int8Array} encodedByte
83
+ * @param {Uint8Array} encodedByte
84
84
  */
85
85
  static deserializeByte(encodedByte) {
86
86
  return import_buffer.Buffer.from(encodedByte).readUint8();
87
87
  }
88
88
  /**
89
- * @param {Int8Array} encodedChar
89
+ * @param {Uint8Array} encodedChar
90
90
  */
91
91
  static deserializeChar(encodedChar) {
92
92
  return import_buffer.Buffer.from(encodedChar).readUint8();
93
93
  }
94
94
  /**
95
- * @param {Int8Array} encodedLongLong
95
+ * @param {Uint8Array} encodedLongLong
96
96
  */
97
97
  static deserializeLongLong(encodedLongLong) {
98
98
  return import_buffer.Buffer.from(encodedLongLong).readBigInt64LE();
99
99
  }
100
100
  /**
101
- * @param {Int8Array} encodedDouble
101
+ * @param {Uint8Array} encodedDouble
102
102
  */
103
103
  static deserializeDouble(encodedDouble) {
104
104
  return import_buffer.Buffer.from(encodedDouble).readDoubleLE();
105
105
  }
106
106
  /**
107
- * @param {Int8Array} encodedULLong
107
+ * @param {Uint8Array} encodedULLong
108
108
  */
109
109
  static deserializeULLong(encodedULLong) {
110
110
  return import_buffer.Buffer.from(encodedULLong).readBigUInt64LE();
111
111
  }
112
112
  /**
113
- * @param {Int8Array} encodedUInt
113
+ * @param {Uint8Array} encodedUInt
114
114
  */
115
115
  static deserializeUInt(encodedUInt) {
116
116
  return import_buffer.Buffer.from(encodedUInt).readUIntLE(0, 4);
@@ -38,14 +38,13 @@ class Receiver {
38
38
  return import_RuntimeLogger.RuntimeLogger.getRuntimeInfo();
39
39
  }
40
40
  /**
41
- * @param {Int8Array} messageByteArray
41
+ * @param {Uint8Array} messageByteArray
42
+ * @returns {Promise<Uint8Array> | Uint8Array}
42
43
  */
43
44
  static sendCommand(messageByteArray) {
44
45
  try {
45
- return new import_CommandSerializer.CommandSerializer().serialize(
46
- new import_Interpreter.Interpreter().process(messageByteArray),
47
- this.connectionData
48
- );
46
+ let command = new import_Interpreter.Interpreter().process(messageByteArray);
47
+ return new import_CommandSerializer.CommandSerializer().serialize(command, this.connectionData);
49
48
  } catch (error) {
50
49
  const exceptionCommand = import_ExceptionSerializer.ExceptionSerializer.serializeException(
51
50
  error,
@@ -55,11 +54,11 @@ class Receiver {
55
54
  }
56
55
  }
57
56
  /**
58
- * @param {Int8Array} messageByteArray
59
- * @returns {Int8Array}
57
+ * @param {Uint8Array} messageByteArray
58
+ * @returns {Promise<Uint8Array> | Uint8Array}
60
59
  */
61
60
  static heartBeat(messageByteArray) {
62
- let response = new Int8Array(2);
61
+ let response = new Uint8Array(2);
63
62
  response[0] = messageByteArray[11];
64
63
  response[1] = messageByteArray[12] - 2;
65
64
  return response;
@@ -24,13 +24,15 @@ module.exports = __toCommonJS(ReceiverNative_exports);
24
24
  var import_Receiver = require("./Receiver.cjs");
25
25
  class ReceiverNative {
26
26
  /**
27
- * @param {Int8Array} messageByteArray
27
+ * @param {Uint8Array} messageByteArray
28
+ * @returns {Promise<Uint8Array> | Uint8Array}
28
29
  */
29
30
  static sendCommand(messageByteArray) {
30
31
  return import_Receiver.Receiver.sendCommand(messageByteArray);
31
32
  }
32
33
  /**
33
- * @param {Int8Array} messageByteArray
34
+ * @param {Uint8Array} messageByteArray
35
+ * @returns {Uint8Array | Promise<Uint8Array>}
34
36
  */
35
37
  static heartBeat(messageByteArray) {
36
38
  return import_Receiver.Receiver.heartBeat(messageByteArray);
@@ -24,8 +24,8 @@ module.exports = __toCommonJS(Transmitter_exports);
24
24
  var import_TransmitterWrapper = require("./TransmitterWrapper.cjs");
25
25
  class Transmitter {
26
26
  /**
27
- * @param {Int8Array} messageArray
28
- * @returns {Int8Array}
27
+ * @param {Uint8Array} messageArray
28
+ * @returns {Uint8Array}
29
29
  */
30
30
  static sendCommand(messageArray) {
31
31
  return import_TransmitterWrapper.TransmitterWrapper.sendCommand(messageArray);
@@ -40,9 +40,9 @@ class TransmitterWebsocket {
40
40
  }
41
41
  /**
42
42
  * @async
43
- * @param {Int8Array} messageByteArray
43
+ * @param {Uint8Array} messageByteArray
44
44
  * @param {IConnectionData} connectionData
45
- * @returns {Promise<Int8Array>} responseByteArray
45
+ * @returns {Promise<Uint8Array>} responseByteArray
46
46
  */
47
47
  static sendCommand(messageByteArray, connectionData) {
48
48
  const { hostname } = connectionData;
@@ -35,9 +35,9 @@ class TransmitterWebsocketBrowser {
35
35
  }
36
36
  /**
37
37
  * @async
38
- * @param {Int8Array} messageByteArray
38
+ * @param {Uint8Array} messageByteArray
39
39
  * @param {IConnectionData} connectionData
40
- * @returns {Promise<Int8Array>} responseByteArray
40
+ * @returns {Promise<Uint8Array>} responseByteArray
41
41
  */
42
42
  static async sendCommand(messageByteArray, connectionData) {
43
43
  const { hostname } = connectionData;
@@ -65,7 +65,8 @@ class TransmitterWrapper {
65
65
  return library.activate(licenseKey);
66
66
  }
67
67
  /**
68
- * @param {Int8Array} messageArray
68
+ * @param {Uint8Array} messageArray
69
+ * @returns {Uint8Array}
69
70
  */
70
71
  static sendCommand(messageArray) {
71
72
  this.loadNativeLibrary();
@@ -62,8 +62,8 @@ class WebSocketClient {
62
62
  /**
63
63
  * Sends messageArray through websocket connection with guaranteed order preservation
64
64
  * @async
65
- * @param {Int8Array} messageArray
66
- * @returns {Promise<Int8Array>}
65
+ * @param {Uint8Array} messageArray
66
+ * @returns {Promise<Uint8Array>}
67
67
  */
68
68
  send(messageArray) {
69
69
  return new Promise((resolve, reject) => {
@@ -104,8 +104,8 @@ class WebSocketClient {
104
104
  * Sends a single message through websocket connection
105
105
  * @private
106
106
  * @async
107
- * @param {Int8Array} messageArray
108
- * @returns {Promise<Int8Array>}
107
+ * @param {Uint8Array} messageArray
108
+ * @returns {Promise<Uint8Array>}
109
109
  */
110
110
  _send(messageArray) {
111
111
  return new Promise((resolve, reject) => {
@@ -60,8 +60,8 @@ class WebSocketClientBrowser {
60
60
  /**
61
61
  * Sends messageArray through websocket connection with guaranteed order preservation
62
62
  * @async
63
- * @param {Int8Array} messageArray
64
- * @returns {Promise<Int8Array>}
63
+ * @param {Uint8Array} messageArray
64
+ * @returns {Promise<Uint8Array>}
65
65
  */
66
66
  send(messageArray) {
67
67
  return new Promise((resolve, reject) => {
@@ -102,8 +102,8 @@ class WebSocketClientBrowser {
102
102
  * Sends a single message through websocket connection
103
103
  * @private
104
104
  * @async
105
- * @param {Int8Array} messageArray
106
- * @returns {Promise<Int8Array>}
105
+ * @param {Uint8Array} messageArray
106
+ * @returns {Promise<Uint8Array>}
107
107
  */
108
108
  _sendSingle(messageArray) {
109
109
  return new Promise((resolve, reject) => {
@@ -162,8 +162,8 @@ class WebSocketClientBrowser {
162
162
  * Sends the data to the WebSocket server and listens for a response.
163
163
  * @private
164
164
  * @param {WebSocket} client
165
- * @param {Int8Array} data
166
- * @param {(value: Int8Array) => void} resolve
165
+ * @param {Uint8Array} data
166
+ * @param {(value: Uint8Array) => void} resolve
167
167
  * @param {(reason?: any) => void} reject
168
168
  */
169
169
  _sendMessage(client, data, resolve, reject) {
@@ -174,7 +174,7 @@ class WebSocketClientBrowser {
174
174
  if (!message?.data) {
175
175
  return reject(new Error("Invalid message received"));
176
176
  }
177
- const byteArray = new Int8Array(message?.data);
177
+ const byteArray = new Uint8Array(message?.data);
178
178
  resolve(byteArray);
179
179
  if (this.isDisconnectedAfterMessage) {
180
180
  this.disconnect();
@@ -37,12 +37,10 @@ class InvocationContext {
37
37
  #connectionData;
38
38
  /** @type {Command | null} */
39
39
  #currentCommand = null;
40
- /** @type {Command | null} */
40
+ /** @type {Command | Promise<Command> | null} */
41
41
  #responseCommand = null;
42
42
  /** @type {boolean} */
43
43
  #isExecuted = false;
44
- /** @type {any | null} */
45
- #resultValue = null;
46
44
  /** @type {Interpreter | null} */
47
45
  #interpreter = null;
48
46
  /**
@@ -59,7 +57,6 @@ class InvocationContext {
59
57
  this.#responseCommand = null;
60
58
  this.#isExecuted = isExecuted;
61
59
  this.#interpreter = null;
62
- this.#resultValue = null;
63
60
  }
64
61
  /**
65
62
  * @param {Command} localCommand
@@ -100,7 +97,18 @@ class InvocationContext {
100
97
  throw new Error("Object is not iterable");
101
98
  }
102
99
  let position = -1;
103
- const arraySize = Number(this.getSize().execute().getValue());
100
+ let arraySize = 0;
101
+ const sizeCtx = (
102
+ /** @type {any} */
103
+ this.getSize().execute()
104
+ );
105
+ if (sizeCtx instanceof Promise) {
106
+ sizeCtx.then((ctx) => {
107
+ arraySize = Number(ctx.getValue());
108
+ });
109
+ } else {
110
+ arraySize = Number(sizeCtx.getValue());
111
+ }
104
112
  return {
105
113
  next: () => ({
106
114
  value: this.getIndex(++position),
@@ -115,7 +123,7 @@ class InvocationContext {
115
123
  * Commands are becoming nested through each invocation of methods on Invocation Context.
116
124
  * Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
117
125
  * Developer can decide on any moment of the materialization for the context taking full control of the chunks of the expression being transferred and processed on target runtime.
118
- * @returns {InvocationContext} the InvocationContext after executing the command.
126
+ * @returns {Promise<InvocationContext> | InvocationContext} the InvocationContext after executing the command.
119
127
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
120
128
  * @method
121
129
  */
@@ -127,18 +135,25 @@ class InvocationContext {
127
135
  this.#interpreter = new import_Interpreter.Interpreter();
128
136
  }
129
137
  this.#responseCommand = this.#interpreter.execute(this.#currentCommand, this.#connectionData);
130
- if (!this.#responseCommand) {
131
- throw new Error("responseCommand is undefined in Invocation Context execute method");
132
- }
133
- if (this.#responseCommand?.commandType === import_CommandType.CommandType.Exception) {
134
- throw import_ExceptionThrower.ExceptionThrower.throwException(this.#responseCommand);
135
- }
136
- if (this.#responseCommand?.commandType === import_CommandType.CommandType.CreateClassInstance) {
137
- this.#currentCommand = this.#responseCommand;
138
- this.#isExecuted = true;
139
- return this;
138
+ const handleResponse = (resolvedResponse) => {
139
+ if (!resolvedResponse) {
140
+ throw new Error("responseCommand is undefined in Invocation Context execute method");
141
+ }
142
+ if (resolvedResponse.commandType === import_CommandType.CommandType.Exception) {
143
+ throw import_ExceptionThrower.ExceptionThrower.throwException(resolvedResponse);
144
+ }
145
+ if (resolvedResponse.commandType === import_CommandType.CommandType.CreateClassInstance) {
146
+ this.#currentCommand = resolvedResponse;
147
+ this.#isExecuted = true;
148
+ return this;
149
+ }
150
+ return new InvocationContext(this.#runtimeName, this.#connectionData, resolvedResponse, true);
151
+ };
152
+ if (this.#responseCommand instanceof Promise) {
153
+ return this.#responseCommand.then(handleResponse);
154
+ } else {
155
+ return handleResponse(this.#responseCommand);
140
156
  }
141
- return new InvocationContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true);
142
157
  }
143
158
  /**
144
159
  * Invokes a static method on the target runtime.
@@ -375,7 +390,7 @@ class InvocationContext {
375
390
  }
376
391
  /**
377
392
  * Retrieves the type of the object from the target runtime.
378
- * @returns {string} The type of the object.
393
+ * @returns {Promise<string> | string} The type of the object.
379
394
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
380
395
  * @method
381
396
  */
@@ -386,7 +401,11 @@ class InvocationContext {
386
401
  this.#connectionData,
387
402
  this.#buildCommand(localCommand)
388
403
  );
389
- const result = invocationContext.execute().getValue();
404
+ const execCtx = (
405
+ /** @type {any} */
406
+ invocationContext.execute()
407
+ );
408
+ const result = execCtx.getValue();
390
409
  return (
391
410
  /** @type {string} */
392
411
  result
@@ -403,36 +422,31 @@ class InvocationContext {
403
422
  }
404
423
  /**
405
424
  * Retrieves an array from the target runtime.
406
- * @returns {InvocationContext} A new InvocationContext instance that wraps the command to retrieve the array.
407
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/arrays-and-collections/retrieve-array)
425
+ * @returns {Promise<any[]>}
408
426
  * @method
409
427
  */
410
428
  retrieveArray() {
411
- let localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.RetrieveArray, []);
412
- let localInvCtx = new InvocationContext(
429
+ const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.RetrieveArray, []);
430
+ const localInvCtx = new InvocationContext(
413
431
  this.#runtimeName,
414
432
  this.#connectionData,
415
433
  this.#buildCommand(localCommand)
416
434
  );
417
435
  localInvCtx.execute();
418
- if (localInvCtx.#responseCommand === null) {
419
- throw new Error("responseCommand is undefined in Invocation Context execute method");
420
- }
421
- return localInvCtx.#responseCommand.payload;
436
+ const extract = (respCommand) => {
437
+ return respCommand.payload;
438
+ };
439
+ return localInvCtx.#responseCommand instanceof Promise ? localInvCtx.#responseCommand.then(extract) : localInvCtx.#responseCommand?.payload;
422
440
  }
423
441
  /**
424
442
  * Returns the primitive value from the target runtime. This could be any primitive type in JavaScript,
425
443
  * such as int, boolean, byte, char, long, double, float, etc.
426
- * @returns {Command} The value of the current command.
444
+ * @returns {unknown} The value of the current command.
427
445
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
428
446
  * @method
429
447
  */
430
- /**
431
- * @returns {unknown}
432
- */
433
448
  getValue() {
434
- this.#resultValue = this.#currentCommand?.payload[0];
435
- return this.#resultValue;
449
+ return this.#currentCommand?.payload[0];
436
450
  }
437
451
  /**
438
452
  * @param {Command} command
@@ -490,8 +504,6 @@ class InvocationWsContext extends InvocationContext {
490
504
  #interpreter;
491
505
  /** @type {boolean} */
492
506
  #isExecuted;
493
- /** @type {any | null} */
494
- #resultValue;
495
507
  /**
496
508
  * @param {RuntimeNameType} runtimeName
497
509
  * @param {IConnectionData} connectionData
@@ -506,7 +518,6 @@ class InvocationWsContext extends InvocationContext {
506
518
  this.#responseCommand = null;
507
519
  this.#isExecuted = isExecuted;
508
520
  this.#interpreter = null;
509
- this.#resultValue = null;
510
521
  }
511
522
  /**
512
523
  * Executes the current command.
@@ -520,7 +531,6 @@ class InvocationWsContext extends InvocationContext {
520
531
  * @async
521
532
  * @method
522
533
  */
523
- // @ts-expect-error
524
534
  async execute() {
525
535
  if (this.#currentCommand === null) {
526
536
  throw new Error("currentCommand is undefined in Invocation Context execute method");
@@ -552,7 +562,6 @@ class InvocationWsContext extends InvocationContext {
552
562
  * @async
553
563
  * @method
554
564
  */
555
- // @ts-expect-error
556
565
  async getResultType() {
557
566
  const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
558
567
  const invocationContext = new InvocationWsContext(