javonet-nodejs-sdk 2.6.4 → 2.6.6

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 (52) 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/RuntimeFactory.cjs +15 -17
  17. package/dist/sdk/tools/ComplexTypeResolver.cjs +28 -3
  18. package/dist/types/core/handler/Handler.d.ts +3 -3
  19. package/dist/types/core/interpreter/Interpreter.d.ts +3 -3
  20. package/dist/types/core/protocol/CommandDeserializer.d.ts +3 -3
  21. package/dist/types/core/protocol/CommandSerializer.d.ts +3 -3
  22. package/dist/types/core/protocol/TypeDeserializer.d.ts +22 -22
  23. package/dist/types/core/receiver/Receiver.d.ts +6 -5
  24. package/dist/types/core/receiver/ReceiverNative.d.ts +6 -4
  25. package/dist/types/core/transmitter/Transmitter.d.ts +3 -3
  26. package/dist/types/core/transmitter/TransmitterWebsocket.d.ts +3 -3
  27. package/dist/types/core/transmitter/TransmitterWebsocketBrowser.d.ts +3 -3
  28. package/dist/types/core/transmitter/TransmitterWrapper.d.ts +3 -2
  29. package/dist/types/core/webSocketClient/WebSocketClient.d.ts +7 -7
  30. package/dist/types/core/webSocketClient/WebSocketClientBrowser.d.ts +9 -9
  31. package/dist/types/sdk/InvocationContext.d.ts +7 -11
  32. package/dist/types/sdk/RuntimeFactory.d.ts +2 -2
  33. package/dist/types/sdk/tools/ComplexTypeResolver.d.ts +2 -2
  34. package/lib/core/handler/Handler.js +18 -4
  35. package/lib/core/handler/LoadLibraryHandler.js +15 -7
  36. package/lib/core/interpreter/Interpreter.js +47 -20
  37. package/lib/core/protocol/CommandDeserializer.js +4 -4
  38. package/lib/core/protocol/CommandSerializer.js +8 -2
  39. package/lib/core/protocol/TypeDeserializer.js +11 -11
  40. package/lib/core/receiver/Receiver.js +7 -8
  41. package/lib/core/receiver/ReceiverNative.js +4 -2
  42. package/lib/core/transmitter/Transmitter.js +2 -2
  43. package/lib/core/transmitter/TransmitterWebsocket.js +2 -2
  44. package/lib/core/transmitter/TransmitterWebsocketBrowser.js +2 -2
  45. package/lib/core/transmitter/TransmitterWrapper.js +2 -1
  46. package/lib/core/webSocketClient/WebSocketClient.js +5 -5
  47. package/lib/core/webSocketClient/WebSocketClientBrowser.js +8 -8
  48. package/lib/sdk/InvocationContext.js +48 -41
  49. package/lib/sdk/RuntimeContext.js +0 -7
  50. package/lib/sdk/RuntimeFactory.js +23 -28
  51. package/lib/sdk/tools/ComplexTypeResolver.js +22 -3
  52. package/package.json +4 -2
@@ -14,10 +14,10 @@ import { Handler } from '../handler/Handler.js'
14
14
  * @typedef {import('../../utils/Command.js').Command} Command
15
15
  */
16
16
 
17
- /** @type {typeof import('../receiver/Receiver.js').Receiver | null} */
18
- let _Receiver = null
19
- /** @type {typeof import('../transmitter/Transmitter.js').Transmitter | null} */
20
- let _Transmitter = null
17
+ /** @type {typeof import('../receiver/Receiver.js').Receiver} */
18
+ let _Receiver
19
+ /** @type {typeof import('../transmitter/Transmitter.js').Transmitter} */
20
+ let _Transmitter
21
21
  /** @type {typeof import('../transmitter/TransmitterWebsocket.js').TransmitterWebsocket | typeof import('../transmitter/TransmitterWebsocketBrowser.js').TransmitterWebsocketBrowser | null} */
22
22
  let _TransmitterWebsocket = null
23
23
 
@@ -48,11 +48,14 @@ export class Interpreter {
48
48
  async executeAsync(command, connectionData) {
49
49
  try {
50
50
  let messageByteArray = new CommandSerializer().serialize(command, connectionData)
51
- /** @type {Int8Array | undefined} */
51
+ /** @type {Uint8Array | undefined} */
52
52
  let responseByteArray = undefined
53
53
 
54
54
  if (connectionData.connectionType === ConnectionType.WEB_SOCKET) {
55
- const _response = await _TransmitterWebsocket?.sendCommand(messageByteArray, connectionData)
55
+ const _response = await _TransmitterWebsocket?.sendCommand(
56
+ await messageByteArray,
57
+ connectionData
58
+ )
56
59
  if (_response) {
57
60
  const command = new CommandDeserializer(_response).deserialize()
58
61
  return command
@@ -69,13 +72,13 @@ export class Interpreter {
69
72
  const { Receiver } = requireDynamic('../receiver/Receiver.js')
70
73
  _Receiver = Receiver
71
74
  }
72
- responseByteArray = await _Receiver?.sendCommand(messageByteArray)
75
+ responseByteArray = await _Receiver?.sendCommand(await messageByteArray)
73
76
  } else {
74
77
  if (!_Transmitter) {
75
78
  const { Transmitter } = requireDynamic('../transmitter/Transmitter.js')
76
79
  _Transmitter = Transmitter
77
80
  }
78
- responseByteArray = await _Transmitter?.sendCommand(messageByteArray)
81
+ responseByteArray = await _Transmitter?.sendCommand(await messageByteArray)
79
82
  }
80
83
  }
81
84
 
@@ -98,37 +101,61 @@ export class Interpreter {
98
101
  execute(command, connectionData) {
99
102
  try {
100
103
  let messageByteArray = new CommandSerializer().serialize(command, connectionData)
101
- /** @type {Int8Array | undefined} */
104
+ /** @type {Promise<Uint8Array> | Uint8Array | undefined} */
102
105
  let responseByteArray = undefined
103
106
 
104
107
  if (connectionData.connectionType === ConnectionType.WEB_SOCKET) {
105
108
  throw new Error('Not supported')
106
109
  }
107
- if (connectionData.connectionType === ConnectionType.IN_MEMORY) {
110
+ else {
108
111
  if (!isNodejsRuntime()) {
109
112
  throw new Error('InMemory is only allowed in Nodejs runtime')
110
113
  }
111
114
 
112
- if (command.runtimeName === RuntimeName.Nodejs) {
115
+ if (command.runtimeName === RuntimeName.Nodejs && connectionData.connectionType === ConnectionType.IN_MEMORY) {
113
116
  if (!_Receiver) {
114
117
  const { Receiver } = requireDynamic('../receiver/Receiver.js')
115
118
  _Receiver = Receiver
116
119
  }
117
- responseByteArray = _Receiver?.sendCommand(messageByteArray)
120
+ if (!_Receiver) {
121
+ throw new Error('Receiver is undefined')
122
+ }
123
+ if (messageByteArray instanceof Uint8Array) {
124
+ responseByteArray = _Receiver.sendCommand(messageByteArray)
125
+ } else {
126
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
127
+ return _Receiver.sendCommand(resolvedMessage)
128
+ })
129
+ }
118
130
  } else {
119
131
  if (!_Transmitter) {
120
132
  const { Transmitter } = requireDynamic('../transmitter/Transmitter.js')
121
133
  _Transmitter = Transmitter
122
134
  }
123
- responseByteArray = _Transmitter?.sendCommand(messageByteArray)
135
+ if (!_Transmitter) {
136
+ throw new Error('Transmitter is undefined')
137
+ }
138
+ if (messageByteArray instanceof Uint8Array) {
139
+ responseByteArray = _Transmitter.sendCommand(messageByteArray)
140
+ } else {
141
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
142
+ return _Transmitter.sendCommand(resolvedMessage)
143
+ })
144
+ }
124
145
  }
125
- }
126
146
 
127
- if (!responseByteArray) {
128
- throw new Error('No response received from Transmitter')
129
- }
147
+ if (!responseByteArray) {
148
+ throw new Error('No response received from Transmitter')
149
+ }
130
150
 
131
- return new CommandDeserializer(responseByteArray).deserialize()
151
+ if (responseByteArray instanceof Promise) {
152
+ return responseByteArray.then((resolvedResponse) => {
153
+ return new CommandDeserializer(resolvedResponse).deserialize()
154
+ })
155
+ } else {
156
+ return new CommandDeserializer(responseByteArray).deserialize()
157
+ }
158
+ }
132
159
  } catch (error) {
133
160
  throw error
134
161
  }
@@ -136,8 +163,8 @@ export class Interpreter {
136
163
 
137
164
  /**
138
165
  *
139
- * @param {Int8Array} messageByteArray
140
- * @returns {Command}
166
+ * @param {Uint8Array} messageByteArray
167
+ * @returns {Promise<Command> | Command}
141
168
  */
142
169
  process(messageByteArray) {
143
170
  try {
@@ -5,11 +5,11 @@ import { TypeDeserializer } from './TypeDeserializer.js'
5
5
 
6
6
  export class CommandDeserializer {
7
7
  /**
8
- * @param {Int8Array} buffer
8
+ * @param {Uint8Array} byteArray
9
9
  */
10
- constructor(buffer) {
11
- this.buffer = buffer
12
- this.command = new Command(buffer[0], buffer[10], [])
10
+ constructor(byteArray) {
11
+ this.buffer = byteArray
12
+ this.command = new Command(this.buffer[0], this.buffer[10], [])
13
13
  this.position = 11
14
14
  }
15
15
 
@@ -11,15 +11,21 @@ import { TypesHandler } from '../../utils/TypesHandler.js'
11
11
  class CommandSerializer {
12
12
  /**
13
13
  * Serializes the root command with connection data and optional runtime version.
14
- * @param {Command} rootCommand
14
+ * @param {Promise<Command> | Command} rootCommand
15
15
  * @param {IConnectionData} connectionData
16
16
  * @param {number} runtimeVersion
17
- * @returns {Int8Array}
17
+ * @returns {Promise<Uint8Array> | Uint8Array}
18
18
  */
19
19
  serialize(rootCommand, connectionData, runtimeVersion = 0) {
20
20
  const buffers = []
21
21
 
22
22
  // Write runtime name and version
23
+ if (rootCommand instanceof Promise) {
24
+ return rootCommand.then(resolvedCommand => {
25
+ return this.serialize(resolvedCommand, connectionData, runtimeVersion)
26
+ })
27
+ }
28
+
23
29
  buffers.push(Uint8Array.of(rootCommand.runtimeName, runtimeVersion))
24
30
 
25
31
  // Write connection data or default zeros
@@ -5,7 +5,7 @@ import { StringEncodingMode } from '../../utils/StringEncodingMode.js'
5
5
 
6
6
  export class TypeDeserializer {
7
7
  /**
8
- * @param {Int8Array} encodedCommand
8
+ * @param {Uint8Array} encodedCommand
9
9
  * @returns {Command}
10
10
  */
11
11
  static deserializeCommand(encodedCommand) {
@@ -14,7 +14,7 @@ export class TypeDeserializer {
14
14
 
15
15
  /**
16
16
  * @param {number} stringEncodingMode
17
- * @param {Int8Array} encodedString
17
+ * @param {Uint8Array} encodedString
18
18
  */
19
19
  static deserializeString(stringEncodingMode, encodedString) {
20
20
  switch (stringEncodingMode) {
@@ -43,7 +43,7 @@ export class TypeDeserializer {
43
43
  }
44
44
 
45
45
  /**
46
- * @param {Int8Array} encodedInt
46
+ * @param {Uint8Array} encodedInt
47
47
  */
48
48
  static deserializeInt(encodedInt) {
49
49
  return (
@@ -55,56 +55,56 @@ export class TypeDeserializer {
55
55
  }
56
56
 
57
57
  /**
58
- * @param {Int8Array} encodedBool
58
+ * @param {Uint8Array} encodedBool
59
59
  */
60
60
  static deserializeBool(encodedBool) {
61
61
  return encodedBool[0] === 1
62
62
  }
63
63
 
64
64
  /**
65
- * @param {Int8Array} encodedFloat
65
+ * @param {Uint8Array} encodedFloat
66
66
  */
67
67
  static deserializeFloat(encodedFloat) {
68
68
  return Buffer.from(encodedFloat).readFloatLE()
69
69
  }
70
70
 
71
71
  /**
72
- * @param {Int8Array} encodedByte
72
+ * @param {Uint8Array} encodedByte
73
73
  */
74
74
  static deserializeByte(encodedByte) {
75
75
  return Buffer.from(encodedByte).readUint8()
76
76
  }
77
77
 
78
78
  /**
79
- * @param {Int8Array} encodedChar
79
+ * @param {Uint8Array} encodedChar
80
80
  */
81
81
  static deserializeChar(encodedChar) {
82
82
  return Buffer.from(encodedChar).readUint8()
83
83
  }
84
84
 
85
85
  /**
86
- * @param {Int8Array} encodedLongLong
86
+ * @param {Uint8Array} encodedLongLong
87
87
  */
88
88
  static deserializeLongLong(encodedLongLong) {
89
89
  return Buffer.from(encodedLongLong).readBigInt64LE()
90
90
  }
91
91
 
92
92
  /**
93
- * @param {Int8Array} encodedDouble
93
+ * @param {Uint8Array} encodedDouble
94
94
  */
95
95
  static deserializeDouble(encodedDouble) {
96
96
  return Buffer.from(encodedDouble).readDoubleLE()
97
97
  }
98
98
 
99
99
  /**
100
- * @param {Int8Array} encodedULLong
100
+ * @param {Uint8Array} encodedULLong
101
101
  */
102
102
  static deserializeULLong(encodedULLong) {
103
103
  return Buffer.from(encodedULLong).readBigUInt64LE()
104
104
  }
105
105
 
106
106
  /**
107
- * @param {Int8Array} encodedUInt
107
+ * @param {Uint8Array} encodedUInt
108
108
  */
109
109
  static deserializeUInt(encodedUInt) {
110
110
  return Buffer.from(encodedUInt).readUIntLE(0, 4)
@@ -18,14 +18,13 @@ export class Receiver {
18
18
  }
19
19
 
20
20
  /**
21
- * @param {Int8Array} messageByteArray
21
+ * @param {Uint8Array} messageByteArray
22
+ * @returns {Promise<Uint8Array> | Uint8Array}
22
23
  */
23
24
  static sendCommand(messageByteArray) {
24
25
  try {
25
- return new CommandSerializer().serialize(
26
- new Interpreter().process(messageByteArray),
27
- this.connectionData
28
- )
26
+ let command = new Interpreter().process(messageByteArray)
27
+ return new CommandSerializer().serialize(command, this.connectionData)
29
28
  } catch (error) {
30
29
  const exceptionCommand = ExceptionSerializer.serializeException(
31
30
  error,
@@ -36,11 +35,11 @@ export class Receiver {
36
35
  }
37
36
 
38
37
  /**
39
- * @param {Int8Array} messageByteArray
40
- * @returns {Int8Array}
38
+ * @param {Uint8Array} messageByteArray
39
+ * @returns {Promise<Uint8Array> | Uint8Array}
41
40
  */
42
41
  static heartBeat(messageByteArray) {
43
- let response = new Int8Array(2)
42
+ let response = new Uint8Array(2)
44
43
  response[0] = messageByteArray[11]
45
44
  response[1] = messageByteArray[12] - 2
46
45
  return response
@@ -3,14 +3,16 @@ import { Receiver } from './Receiver.js'
3
3
 
4
4
  export class ReceiverNative {
5
5
  /**
6
- * @param {Int8Array} messageByteArray
6
+ * @param {Uint8Array} messageByteArray
7
+ * @returns {Promise<Uint8Array> | Uint8Array}
7
8
  */
8
9
  static sendCommand(messageByteArray) {
9
10
  return Receiver.sendCommand(messageByteArray)
10
11
  }
11
12
 
12
13
  /**
13
- * @param {Int8Array} messageByteArray
14
+ * @param {Uint8Array} messageByteArray
15
+ * @returns {Uint8Array | Promise<Uint8Array>}
14
16
  */
15
17
  static heartBeat(messageByteArray) {
16
18
  return Receiver.heartBeat(messageByteArray)
@@ -3,8 +3,8 @@ import { TransmitterWrapper } from './TransmitterWrapper.js'
3
3
 
4
4
  export class Transmitter {
5
5
  /**
6
- * @param {Int8Array} messageArray
7
- * @returns {Int8Array}
6
+ * @param {Uint8Array} messageArray
7
+ * @returns {Uint8Array}
8
8
  */
9
9
  static sendCommand(messageArray) {
10
10
  return TransmitterWrapper.sendCommand(messageArray)
@@ -22,9 +22,9 @@ export class TransmitterWebsocket {
22
22
 
23
23
  /**
24
24
  * @async
25
- * @param {Int8Array} messageByteArray
25
+ * @param {Uint8Array} messageByteArray
26
26
  * @param {IConnectionData} connectionData
27
- * @returns {Promise<Int8Array>} responseByteArray
27
+ * @returns {Promise<Uint8Array>} responseByteArray
28
28
  */
29
29
  static sendCommand(messageByteArray, connectionData) {
30
30
  const { hostname } = connectionData
@@ -17,9 +17,9 @@ export class TransmitterWebsocketBrowser {
17
17
 
18
18
  /**
19
19
  * @async
20
- * @param {Int8Array} messageByteArray
20
+ * @param {Uint8Array} messageByteArray
21
21
  * @param {IConnectionData} connectionData
22
- * @returns {Promise<Int8Array>} responseByteArray
22
+ * @returns {Promise<Uint8Array>} responseByteArray
23
23
  */
24
24
  static async sendCommand(messageByteArray, connectionData) {
25
25
  const { hostname } = connectionData
@@ -54,7 +54,8 @@ class TransmitterWrapper {
54
54
  }
55
55
 
56
56
  /**
57
- * @param {Int8Array} messageArray
57
+ * @param {Uint8Array} messageArray
58
+ * @returns {Uint8Array}
58
59
  */
59
60
  static sendCommand(messageArray) {
60
61
  this.loadNativeLibrary()
@@ -36,7 +36,7 @@ let WebSocket = null
36
36
  /** @type {Record<string, wsClient>} */
37
37
  export const clients = {}
38
38
 
39
- /** @type {Record<string, Array<{resolve: Function, reject: Function, messageArray: Int8Array}>>} */
39
+ /** @type {Record<string, Array<{resolve: Function, reject: Function, messageArray: Uint8Array}>>} */
40
40
  export const messageQueue = {}
41
41
 
42
42
  /** @type {Record<string, boolean>} */
@@ -69,8 +69,8 @@ class WebSocketClient {
69
69
  /**
70
70
  * Sends messageArray through websocket connection with guaranteed order preservation
71
71
  * @async
72
- * @param {Int8Array} messageArray
73
- * @returns {Promise<Int8Array>}
72
+ * @param {Uint8Array} messageArray
73
+ * @returns {Promise<Uint8Array>}
74
74
  */
75
75
  send(messageArray) {
76
76
  return new Promise((resolve, reject) => {
@@ -117,8 +117,8 @@ class WebSocketClient {
117
117
  * Sends a single message through websocket connection
118
118
  * @private
119
119
  * @async
120
- * @param {Int8Array} messageArray
121
- * @returns {Promise<Int8Array>}
120
+ * @param {Uint8Array} messageArray
121
+ * @returns {Promise<Uint8Array>}
122
122
  */
123
123
  _send(messageArray) {
124
124
  return new Promise((resolve, reject) => {
@@ -25,7 +25,7 @@ if (isBrowserRuntime()) {
25
25
  /** @type {Record<string, WebSocket>} */
26
26
  export const clients = {}
27
27
 
28
- /** @type {Record<string, Array<{resolve: Function, reject: Function, messageArray: Int8Array}>>} */
28
+ /** @type {Record<string, Array<{resolve: Function, reject: Function, messageArray: Uint8Array}>>} */
29
29
  export const messageQueue = {}
30
30
 
31
31
  /** @type {Record<string, boolean>} */
@@ -59,8 +59,8 @@ class WebSocketClientBrowser {
59
59
  /**
60
60
  * Sends messageArray through websocket connection with guaranteed order preservation
61
61
  * @async
62
- * @param {Int8Array} messageArray
63
- * @returns {Promise<Int8Array>}
62
+ * @param {Uint8Array} messageArray
63
+ * @returns {Promise<Uint8Array>}
64
64
  */
65
65
  send(messageArray) {
66
66
  return new Promise((resolve, reject) => {
@@ -106,8 +106,8 @@ class WebSocketClientBrowser {
106
106
  * Sends a single message through websocket connection
107
107
  * @private
108
108
  * @async
109
- * @param {Int8Array} messageArray
110
- * @returns {Promise<Int8Array>}
109
+ * @param {Uint8Array} messageArray
110
+ * @returns {Promise<Uint8Array>}
111
111
  */
112
112
  _sendSingle(messageArray) {
113
113
  return new Promise((resolve, reject) => {
@@ -174,8 +174,8 @@ class WebSocketClientBrowser {
174
174
  * Sends the data to the WebSocket server and listens for a response.
175
175
  * @private
176
176
  * @param {WebSocket} client
177
- * @param {Int8Array} data
178
- * @param {(value: Int8Array) => void} resolve
177
+ * @param {Uint8Array} data
178
+ * @param {(value: Uint8Array) => void} resolve
179
179
  * @param {(reason?: any) => void} reject
180
180
  */
181
181
  _sendMessage(client, data, resolve, reject) {
@@ -188,7 +188,7 @@ class WebSocketClientBrowser {
188
188
  return reject(new Error('Invalid message received'))
189
189
  }
190
190
 
191
- const byteArray = new Int8Array(message?.data)
191
+ const byteArray = new Uint8Array(message?.data)
192
192
  resolve(byteArray)
193
193
 
194
194
  if (this.isDisconnectedAfterMessage) {
@@ -27,12 +27,10 @@ class InvocationContext {
27
27
  #connectionData
28
28
  /** @type {Command | null} */
29
29
  #currentCommand = null
30
- /** @type {Command | null} */
30
+ /** @type {Command | Promise<Command> | null} */
31
31
  #responseCommand = null
32
32
  /** @type {boolean} */
33
33
  #isExecuted = false
34
- /** @type {any | null} */
35
- #resultValue = null
36
34
  /** @type {Interpreter | null} */
37
35
  #interpreter = null
38
36
 
@@ -50,7 +48,6 @@ class InvocationContext {
50
48
  this.#responseCommand = null
51
49
  this.#isExecuted = isExecuted
52
50
  this.#interpreter = null
53
- this.#resultValue = null
54
51
  }
55
52
 
56
53
  /**
@@ -59,7 +56,6 @@ class InvocationContext {
59
56
  */
60
57
  #createInstanceContext(localCommand) {
61
58
  if (this.#connectionData.connectionType === ConnectionType.WEB_SOCKET) {
62
- // @ts-expect-error
63
59
  return new InvocationWsContext(
64
60
  this.#runtimeName,
65
61
  this.#connectionData,
@@ -96,7 +92,17 @@ class InvocationContext {
96
92
  throw new Error('Object is not iterable')
97
93
  }
98
94
  let position = -1
99
- const arraySize = Number(this.getSize().execute().getValue())
95
+ /** @type {number} */
96
+ let arraySize = 0
97
+ /** @type {InvocationContext | Promise<InvocationContext>} */
98
+ const sizeCtx = /** @type {any} */ (this.getSize().execute())
99
+ if (sizeCtx instanceof Promise) {
100
+ sizeCtx.then((ctx) => {
101
+ arraySize = Number(ctx.getValue())
102
+ })
103
+ } else {
104
+ arraySize = Number(sizeCtx.getValue())
105
+ }
100
106
 
101
107
  return {
102
108
  next: () => ({
@@ -113,7 +119,7 @@ class InvocationContext {
113
119
  * Commands are becoming nested through each invocation of methods on Invocation Context.
114
120
  * Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
115
121
  * 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.
116
- * @returns {InvocationContext} the InvocationContext after executing the command.
122
+ * @returns {Promise<InvocationContext> | InvocationContext} the InvocationContext after executing the command.
117
123
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
118
124
  * @method
119
125
  */
@@ -125,22 +131,29 @@ class InvocationContext {
125
131
  if (!this.#interpreter) {
126
132
  this.#interpreter = new Interpreter()
127
133
  }
128
- //@ts-expect-error
134
+
129
135
  this.#responseCommand = this.#interpreter.execute(this.#currentCommand, this.#connectionData)
130
136
 
131
- if (!this.#responseCommand) {
132
- throw new Error('responseCommand is undefined in Invocation Context execute method')
133
- }
134
- if (this.#responseCommand?.commandType === CommandType.Exception) {
135
- throw ExceptionThrower.throwException(this.#responseCommand)
136
- }
137
- if (this.#responseCommand?.commandType === CommandType.CreateClassInstance) {
138
- this.#currentCommand = this.#responseCommand
139
- this.#isExecuted = true
140
- return this
137
+ const handleResponse = (/** @type {Command } */ resolvedResponse) => {
138
+ if (!resolvedResponse) {
139
+ throw new Error('responseCommand is undefined in Invocation Context execute method')
140
+ }
141
+ if (resolvedResponse.commandType === CommandType.Exception) {
142
+ throw ExceptionThrower.throwException(resolvedResponse)
143
+ }
144
+ if (resolvedResponse.commandType === CommandType.CreateClassInstance) {
145
+ this.#currentCommand = resolvedResponse
146
+ this.#isExecuted = true
147
+ return this
148
+ }
149
+ return new InvocationContext(this.#runtimeName, this.#connectionData, resolvedResponse, true)
141
150
  }
142
151
 
143
- return new InvocationContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true)
152
+ if (this.#responseCommand instanceof Promise) {
153
+ return this.#responseCommand.then(handleResponse)
154
+ } else {
155
+ return handleResponse(this.#responseCommand)
156
+ }
144
157
  }
145
158
 
146
159
  /**
@@ -397,7 +410,7 @@ class InvocationContext {
397
410
 
398
411
  /**
399
412
  * Retrieves the type of the object from the target runtime.
400
- * @returns {string} The type of the object.
413
+ * @returns {Promise<string> | string} The type of the object.
401
414
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
402
415
  * @method
403
416
  */
@@ -408,7 +421,9 @@ class InvocationContext {
408
421
  this.#connectionData,
409
422
  this.#buildCommand(localCommand)
410
423
  )
411
- const result = invocationContext.execute().getValue()
424
+ /** @type {InvocationContext} */
425
+ const execCtx = /** @type {any} */ (invocationContext.execute())
426
+ const result = execCtx.getValue()
412
427
  return /** @type {string} */ (result)
413
428
  }
414
429
 
@@ -424,39 +439,36 @@ class InvocationContext {
424
439
 
425
440
  /**
426
441
  * Retrieves an array from the target runtime.
427
- * @returns {InvocationContext} A new InvocationContext instance that wraps the command to retrieve the array.
428
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/arrays-and-collections/retrieve-array)
442
+ * @returns {Promise<any[]>}
429
443
  * @method
430
444
  */
431
445
  retrieveArray() {
432
- let localCommand = new Command(this.#runtimeName, CommandType.RetrieveArray, [])
433
- let localInvCtx = new InvocationContext(
446
+ const localCommand = new Command(this.#runtimeName, CommandType.RetrieveArray, [])
447
+ const localInvCtx = new InvocationContext(
434
448
  this.#runtimeName,
435
449
  this.#connectionData,
436
450
  this.#buildCommand(localCommand)
437
451
  )
438
- localInvCtx.execute()
439
452
 
440
- if (localInvCtx.#responseCommand === null) {
441
- throw new Error('responseCommand is undefined in Invocation Context execute method')
453
+ localInvCtx.execute() // Promise<InvocationContext> | InvocationContext
454
+
455
+ const extract = (/** @type {Command} */ respCommand) => {
456
+ return respCommand.payload
442
457
  }
443
- return localInvCtx.#responseCommand.payload
458
+
459
+ // Normalize to Promise
460
+ return localInvCtx.#responseCommand instanceof Promise ? localInvCtx.#responseCommand.then(extract) : localInvCtx.#responseCommand?.payload
444
461
  }
445
462
 
446
463
  /**
447
464
  * Returns the primitive value from the target runtime. This could be any primitive type in JavaScript,
448
465
  * such as int, boolean, byte, char, long, double, float, etc.
449
- * @returns {Command} The value of the current command.
466
+ * @returns {unknown} The value of the current command.
450
467
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
451
468
  * @method
452
469
  */
453
-
454
- /**
455
- * @returns {unknown}
456
- */
457
470
  getValue() {
458
- this.#resultValue = this.#currentCommand?.payload[0]
459
- return this.#resultValue
471
+ return this.#currentCommand?.payload[0]
460
472
  }
461
473
 
462
474
  /**
@@ -522,8 +534,6 @@ class InvocationWsContext extends InvocationContext {
522
534
  #interpreter
523
535
  /** @type {boolean} */
524
536
  #isExecuted
525
- /** @type {any | null} */
526
- #resultValue
527
537
 
528
538
  /**
529
539
  * @param {RuntimeNameType} runtimeName
@@ -540,7 +550,6 @@ class InvocationWsContext extends InvocationContext {
540
550
  this.#responseCommand = null
541
551
  this.#isExecuted = isExecuted
542
552
  this.#interpreter = null
543
- this.#resultValue = null
544
553
  }
545
554
 
546
555
  /**
@@ -555,7 +564,6 @@ class InvocationWsContext extends InvocationContext {
555
564
  * @async
556
565
  * @method
557
566
  */
558
- // @ts-expect-error
559
567
  async execute() {
560
568
  if (this.#currentCommand === null) {
561
569
  throw new Error('currentCommand is undefined in Invocation Context execute method')
@@ -591,7 +599,6 @@ class InvocationWsContext extends InvocationContext {
591
599
  * @async
592
600
  * @method
593
601
  */
594
- // @ts-expect-error
595
602
  async getResultType() {
596
603
  const localCommand = new Command(this.#runtimeName, CommandType.GetResultType, [])
597
604
  const invocationContext = new InvocationWsContext(