javonet-nodejs-sdk 2.5.16 → 2.5.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/delegatesCache/DelegatesCache.cjs +1 -5
- package/dist/core/handler/AbstractHandler.cjs +24 -9
- package/dist/core/handler/ArrayGetItemHandler.cjs +5 -4
- package/dist/core/handler/ArrayGetRankHandler.cjs +4 -3
- package/dist/core/handler/ArrayGetSizeHandler.cjs +4 -3
- package/dist/core/handler/ArrayHandler.cjs +3 -0
- package/dist/core/handler/ArraySetItemHandler.cjs +5 -4
- package/dist/core/handler/CastingHandler.cjs +3 -1
- package/dist/core/handler/ConvertTypeHandler.cjs +4 -4
- package/dist/core/handler/CreateClassInstanceHandler.cjs +6 -5
- package/dist/core/handler/DestructReferenceHandler.cjs +3 -0
- package/dist/core/handler/EnableNamespaceHandler.cjs +3 -0
- package/dist/core/handler/EnableTypeHandler.cjs +4 -3
- package/dist/core/handler/GetGlobalStaticFieldHandler.cjs +4 -3
- package/dist/core/handler/GetInstanceFieldHandler.cjs +4 -3
- package/dist/core/handler/GetInstanceMethodAsDelegateHandler.cjs +15 -4
- package/dist/core/handler/GetStaticFieldHandler.cjs +5 -3
- package/dist/core/handler/GetStaticMethodAsDelegateHandler.cjs +10 -10
- package/dist/core/handler/GetTypeHandler.cjs +10 -2
- package/dist/core/handler/Handler.cjs +8 -11
- package/dist/core/handler/InvokeGlobalFunctionHandler.cjs +4 -3
- package/dist/core/handler/InvokeInstanceMethodHandler.cjs +4 -3
- package/dist/core/handler/InvokeStaticMethodHandler.cjs +4 -3
- package/dist/core/handler/LoadLibraryHandler.cjs +11 -10
- package/dist/core/handler/PassDelegateHandler.cjs +2 -4
- package/dist/core/handler/SetGlobalStaticFieldHandler.cjs +4 -3
- package/dist/core/handler/SetInstanceFieldHandler.cjs +4 -3
- package/dist/core/handler/SetStaticFieldHandler.cjs +4 -3
- package/dist/core/handler/ValueHandler.cjs +4 -0
- package/dist/core/interpreter/Interpreter.cjs +29 -17
- package/dist/core/namespaceCache/NamespaceCache.cjs +19 -10
- package/dist/core/protocol/CommandDeserializer.cjs +10 -2
- package/dist/core/protocol/CommandSerializer.cjs +24 -4
- package/dist/core/protocol/TypeDeserializer.cjs +35 -0
- package/dist/core/protocol/TypeSerializer.cjs +51 -7
- package/dist/core/receiver/Receiver.cjs +3 -5
- package/dist/core/receiver/ReceiverNative.cjs +6 -0
- package/dist/core/transmitter/Transmitter.cjs +19 -5
- package/dist/core/transmitter/TransmitterWebsocket.cjs +8 -5
- package/dist/core/transmitter/TransmitterWebsocketBrowser.cjs +1 -1
- package/dist/core/transmitter/TransmitterWrapper.cjs +25 -8
- package/dist/core/typeCache/TypeCache.cjs +15 -10
- package/dist/core/webSocketClient/WebSocketClient.cjs +22 -12
- package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +2 -2
- package/dist/sdk/ConfigRuntimeFactory.cjs +92 -98
- package/dist/sdk/InvocationContext.cjs +229 -203
- package/dist/sdk/Javonet.cjs +14 -33
- package/dist/sdk/RuntimeContext.cjs +138 -99
- package/dist/sdk/RuntimeFactory.cjs +3 -0
- package/dist/sdk/tools/ActivationHelper.cjs +66 -0
- package/dist/sdk/tools/JsonResolver.cjs +214 -0
- package/dist/types/core/handler/AbstractHandler.d.ts +23 -4
- package/dist/types/core/handler/ArrayGetItemHandler.d.ts +8 -1
- package/dist/types/core/handler/ArrayGetRankHandler.d.ts +8 -1
- package/dist/types/core/handler/ArrayGetSizeHandler.d.ts +8 -1
- package/dist/types/core/handler/ArrayHandler.d.ts +8 -1
- package/dist/types/core/handler/ArraySetItemHandler.d.ts +8 -1
- package/dist/types/core/handler/CastingHandler.d.ts +4 -0
- package/dist/types/core/handler/ConvertTypeHandler.d.ts +8 -4
- package/dist/types/core/handler/CreateClassInstanceHandler.d.ts +8 -1
- package/dist/types/core/handler/DestructReferenceHandler.d.ts +8 -1
- package/dist/types/core/handler/EnableNamespaceHandler.d.ts +8 -1
- package/dist/types/core/handler/EnableTypeHandler.d.ts +8 -1
- package/dist/types/core/handler/GetGlobalStaticFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/GetInstanceFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/GetStaticFieldHandler.d.ts +9 -1
- package/dist/types/core/handler/GetStaticMethodAsDelegateHandler.d.ts +4 -3
- package/dist/types/core/handler/GetTypeHandler.d.ts +17 -8
- package/dist/types/core/handler/Handler.d.ts +8 -8
- package/dist/types/core/handler/InvokeDelegateHandler.d.ts +4 -0
- package/dist/types/core/handler/InvokeGlobalFunctionHandler.d.ts +8 -1
- package/dist/types/core/handler/InvokeInstanceMethodHandler.d.ts +8 -1
- package/dist/types/core/handler/InvokeStaticMethodHandler.d.ts +8 -1
- package/dist/types/core/handler/LoadLibraryHandler.d.ts +8 -3
- package/dist/types/core/handler/SetGlobalStaticFieldHandler.d.ts +4 -0
- package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/SetStaticFieldHandler.d.ts +8 -1
- package/dist/types/core/handler/ValueHandler.d.ts +9 -1
- package/dist/types/core/interpreter/Interpreter.d.ts +11 -10
- package/dist/types/core/namespaceCache/NamespaceCache.d.ts +17 -5
- package/dist/types/core/protocol/CommandDeserializer.d.ts +10 -3
- package/dist/types/core/protocol/CommandSerializer.d.ts +19 -2
- package/dist/types/core/protocol/TypeDeserializer.d.ts +46 -11
- package/dist/types/core/protocol/TypeSerializer.d.ts +53 -13
- package/dist/types/core/receiver/Receiver.d.ts +2 -2
- package/dist/types/core/receiver/ReceiverNative.d.ts +8 -2
- package/dist/types/core/transmitter/Transmitter.d.ts +20 -4
- package/dist/types/core/transmitter/TransmitterWebsocket.d.ts +8 -4
- package/dist/types/core/transmitter/TransmitterWebsocketBrowser.d.ts +4 -7
- package/dist/types/core/transmitter/TransmitterWrapper.d.ts +12 -3
- package/dist/types/core/typeCache/TypeCache.d.ts +15 -5
- package/dist/types/core/webSocketClient/WebSocketClient.d.ts +17 -21
- package/dist/types/sdk/ConfigRuntimeFactory.d.ts +9 -6
- package/dist/types/sdk/InvocationContext.d.ts +38 -6
- package/dist/types/sdk/Javonet.d.ts +12 -7
- package/dist/types/sdk/RuntimeContext.d.ts +23 -7
- package/dist/types/sdk/RuntimeFactory.d.ts +9 -2
- package/dist/types/sdk/tools/ActivationHelper.d.ts +20 -0
- package/dist/types/sdk/tools/JsonResolver.d.ts +87 -0
- package/dist/types/utils/Command.d.ts +18 -14
- package/dist/types/utils/CreateRequire.browser.d.ts +1 -0
- package/dist/types/utils/CreateRequire.node.d.ts +2 -0
- package/dist/types/utils/CustomError.d.ts +5 -1
- package/dist/types/utils/Runtime.d.ts +2 -3
- package/dist/types/utils/RuntimeNameHandler.d.ts +6 -2
- package/dist/types/utils/Type.d.ts +1 -0
- package/dist/types/utils/TypesHandler.d.ts +16 -0
- package/dist/types/utils/UtilsConst.d.ts +32 -0
- package/dist/types/utils/connectionData/IConnectionData.d.ts +16 -3
- package/dist/types/utils/connectionData/InMemoryConnectionData.d.ts +4 -3
- package/dist/types/utils/connectionData/WsConnectionData.d.ts +7 -10
- package/dist/types/utils/nodejs/connectionData/TcpConnectionData.d.ts +17 -10
- package/dist/utils/Command.cjs +9 -9
- package/dist/utils/CreateRequire.browser.cjs +30 -0
- package/dist/utils/CreateRequire.node.cjs +28 -0
- package/dist/utils/CustomError.cjs +4 -0
- package/dist/utils/Runtime.cjs +24 -18
- package/dist/utils/RuntimeLogger.cjs +2 -4
- package/dist/utils/RuntimeLoggerBrowser.cjs +1 -3
- package/dist/utils/RuntimeNameHandler.cjs +1 -1
- package/dist/utils/Type.cjs +2 -1
- package/dist/utils/TypesHandler.cjs +55 -0
- package/dist/utils/UtilsConst.cjs +101 -0
- package/dist/utils/connectionData/IConnectionData.cjs +9 -0
- package/dist/utils/connectionData/InMemoryConnectionData.cjs +10 -0
- package/dist/utils/connectionData/WsConnectionData.cjs +4 -0
- package/dist/utils/nodejs/connectionData/TcpConnectionData.cjs +45 -25
- package/lib/core/delegatesCache/DelegatesCache.js +1 -0
- package/lib/core/handler/AbstractHandler.js +27 -9
- package/lib/core/handler/ArrayGetItemHandler.js +9 -1
- package/lib/core/handler/ArrayGetRankHandler.js +9 -0
- package/lib/core/handler/ArrayGetSizeHandler.js +8 -0
- package/lib/core/handler/ArrayHandler.js +8 -0
- package/lib/core/handler/ArraySetItemHandler.js +11 -1
- package/lib/core/handler/CastingHandler.js +8 -1
- package/lib/core/handler/ConvertTypeHandler.js +9 -4
- package/lib/core/handler/CreateClassInstanceHandler.js +10 -4
- package/lib/core/handler/DestructReferenceHandler.js +8 -0
- package/lib/core/handler/EnableNamespaceHandler.js +8 -0
- package/lib/core/handler/EnableTypeHandler.js +8 -0
- package/lib/core/handler/GetGlobalStaticFieldHandler.js +9 -0
- package/lib/core/handler/GetInstanceFieldHandler.js +8 -0
- package/lib/core/handler/GetInstanceMethodAsDelegateHandler.js +9 -4
- package/lib/core/handler/GetStaticFieldHandler.js +9 -0
- package/lib/core/handler/GetStaticMethodAsDelegateHandler.js +8 -7
- package/lib/core/handler/GetTypeHandler.js +15 -5
- package/lib/core/handler/Handler.js +13 -18
- package/lib/core/handler/InvokeDelegateHandler.js +5 -0
- package/lib/core/handler/InvokeGlobalFunctionHandler.js +11 -1
- package/lib/core/handler/InvokeInstanceMethodHandler.js +8 -0
- package/lib/core/handler/InvokeStaticMethodHandler.js +8 -0
- package/lib/core/handler/LoadLibraryHandler.js +11 -0
- package/lib/core/handler/SetGlobalStaticFieldHandler.js +10 -0
- package/lib/core/handler/SetInstanceFieldHandler.js +7 -0
- package/lib/core/handler/SetStaticFieldHandler.js +8 -0
- package/lib/core/handler/ValueHandler.js +9 -0
- package/lib/core/interpreter/Interpreter.js +42 -24
- package/lib/core/namespaceCache/NamespaceCache.js +14 -0
- package/lib/core/protocol/CommandDeserializer.js +11 -2
- package/lib/core/protocol/CommandSerializer.js +40 -9
- package/lib/core/protocol/TypeDeserializer.js +36 -0
- package/lib/core/protocol/TypeSerializer.js +62 -7
- package/lib/core/receiver/Receiver.js +3 -2
- package/lib/core/receiver/ReceiverNative.js +8 -0
- package/lib/core/transmitter/Transmitter.js +18 -1
- package/lib/core/transmitter/TransmitterWebsocket.js +12 -5
- package/lib/core/transmitter/TransmitterWebsocketBrowser.js +2 -4
- package/lib/core/transmitter/TransmitterWrapper.js +27 -6
- package/lib/core/typeCache/TypeCache.js +9 -0
- package/lib/core/webSocketClient/WebSocketClient.js +33 -30
- package/lib/core/webSocketClient/WebSocketClientBrowser.js +5 -6
- package/lib/sdk/ConfigRuntimeFactory.js +70 -68
- package/lib/sdk/InvocationContext.js +94 -26
- package/lib/sdk/Javonet.js +18 -36
- package/lib/sdk/RuntimeContext.js +109 -29
- package/lib/sdk/RuntimeFactory.js +7 -0
- package/lib/sdk/tools/ActivationHelper.js +51 -0
- package/lib/sdk/tools/JsonResolver.js +226 -0
- package/lib/types.d.ts +57 -0
- package/lib/utils/Command.js +14 -9
- package/lib/utils/CreateRequire.browser.js +5 -0
- package/lib/utils/CreateRequire.node.js +3 -0
- package/lib/utils/CustomError.js +5 -0
- package/lib/utils/Runtime.js +25 -6
- package/lib/utils/RuntimeLogger.js +3 -0
- package/lib/utils/RuntimeNameHandler.js +6 -1
- package/lib/utils/Type.js +2 -1
- package/lib/utils/TypesHandler.js +35 -0
- package/lib/utils/UtilsConst.js +88 -0
- package/lib/utils/connectionData/IConnectionData.js +14 -0
- package/lib/utils/connectionData/InMemoryConnectionData.js +15 -0
- package/lib/utils/connectionData/WsConnectionData.js +9 -0
- package/lib/utils/nodejs/connectionData/TcpConnectionData.js +35 -5
- package/package.json +13 -3
- package/dist/sdk/tools/browser/ConfigSourceResolver.cjs +0 -153
- package/dist/sdk/tools/nodejs/JsonFileResolver.cjs +0 -120
- package/dist/types/sdk/tools/browser/ConfigSourceResolver.d.ts +0 -46
- package/dist/types/sdk/tools/nodejs/JsonFileResolver.d.ts +0 -13
- package/dist/types/utils/nodejs/TypesConverter.d.ts +0 -48
- package/dist/utils/nodejs/TypesConverter.cjs +0 -102
- package/lib/declarations.d.ts +0 -35
- package/lib/sdk/tools/browser/ConfigSourceResolver.js +0 -146
- package/lib/sdk/tools/nodejs/JsonFileResolver.js +0 -106
- package/lib/utils/nodejs/TypesConverter.js +0 -91
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//@ts-check
|
|
1
2
|
import { delegatesCacheInstance } from '../core/delegatesCache/DelegatesCache.js'
|
|
2
3
|
import { Interpreter } from '../core/interpreter/Interpreter.js'
|
|
3
4
|
import { Command } from '../utils/Command.js'
|
|
@@ -5,6 +6,12 @@ import { CommandType } from '../utils/CommandType.js'
|
|
|
5
6
|
import { ConnectionType } from '../utils/ConnectionType.js'
|
|
6
7
|
import { ExceptionThrower } from '../utils/exception/ExceptionThrower.js'
|
|
7
8
|
import { RuntimeName } from '../utils/RuntimeName.js'
|
|
9
|
+
import { TypesHandler } from '../utils/TypesHandler.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import('../types.d.ts').RuntimeName} RuntimeNameType
|
|
13
|
+
* @typedef {import('../utils/connectionData/IConnectionData.js').IConnectionData} IConnectionData
|
|
14
|
+
*/
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* InvocationContext is a class that represents a context for invoking commands.
|
|
@@ -14,15 +21,28 @@ import { RuntimeName } from '../utils/RuntimeName.js'
|
|
|
14
21
|
* @class
|
|
15
22
|
*/
|
|
16
23
|
class InvocationContext {
|
|
24
|
+
/** @type {RuntimeNameType} */
|
|
17
25
|
#runtimeName
|
|
26
|
+
/** @type {IConnectionData} */
|
|
18
27
|
#connectionData
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
#
|
|
28
|
+
/** @type {Command | null} */
|
|
29
|
+
#currentCommand = null
|
|
30
|
+
/** @type {Command | null} */
|
|
31
|
+
#responseCommand = null
|
|
32
|
+
/** @type {boolean} */
|
|
33
|
+
#isExecuted = false
|
|
34
|
+
/** @type {any | null} */
|
|
35
|
+
#resultValue = null
|
|
36
|
+
/** @type {Interpreter | null} */
|
|
37
|
+
#interpreter = null
|
|
25
38
|
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param {RuntimeNameType} runtimeName
|
|
42
|
+
* @param {IConnectionData} connectionData
|
|
43
|
+
* @param {Command} command
|
|
44
|
+
* @param {boolean} isExecuted
|
|
45
|
+
*/
|
|
26
46
|
constructor(runtimeName, connectionData, command, isExecuted = false) {
|
|
27
47
|
this.#runtimeName = runtimeName
|
|
28
48
|
this.#connectionData = connectionData
|
|
@@ -33,8 +53,13 @@ class InvocationContext {
|
|
|
33
53
|
this.#resultValue = null
|
|
34
54
|
}
|
|
35
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @param {Command} localCommand
|
|
58
|
+
* @returns {InvocationContext}
|
|
59
|
+
*/
|
|
36
60
|
#createInstanceContext(localCommand) {
|
|
37
61
|
if (this.#connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
62
|
+
// @ts-expect-error
|
|
38
63
|
return new InvocationWsContext(
|
|
39
64
|
this.#runtimeName,
|
|
40
65
|
this.#connectionData,
|
|
@@ -48,6 +73,9 @@ class InvocationContext {
|
|
|
48
73
|
)
|
|
49
74
|
}
|
|
50
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @returns {Command|null}
|
|
78
|
+
*/
|
|
51
79
|
get_current_command() {
|
|
52
80
|
return this.#currentCommand
|
|
53
81
|
}
|
|
@@ -63,12 +91,12 @@ class InvocationContext {
|
|
|
63
91
|
// }
|
|
64
92
|
//}
|
|
65
93
|
|
|
66
|
-
[Symbol.iterator] =
|
|
67
|
-
if (this.#currentCommand
|
|
94
|
+
[Symbol.iterator] = () => {
|
|
95
|
+
if (this.#currentCommand?.commandType !== CommandType.Reference) {
|
|
68
96
|
throw new Error('Object is not iterable')
|
|
69
97
|
}
|
|
70
98
|
let position = -1
|
|
71
|
-
|
|
99
|
+
const arraySize = Number(this.getSize().execute().getValue())
|
|
72
100
|
|
|
73
101
|
return {
|
|
74
102
|
next: () => ({
|
|
@@ -90,21 +118,25 @@ class InvocationContext {
|
|
|
90
118
|
* @method
|
|
91
119
|
*/
|
|
92
120
|
execute() {
|
|
121
|
+
if (this.#currentCommand === null) {
|
|
122
|
+
throw new Error('currentCommand is undefined in Invocation Context execute method')
|
|
123
|
+
}
|
|
124
|
+
|
|
93
125
|
this.#interpreter = new Interpreter()
|
|
126
|
+
//@ts-expect-error
|
|
94
127
|
this.#responseCommand = this.#interpreter.execute(this.#currentCommand, this.#connectionData)
|
|
95
|
-
|
|
128
|
+
|
|
129
|
+
if (!this.#responseCommand) {
|
|
96
130
|
throw new Error('responseCommand is undefined in Invocation Context execute method')
|
|
97
131
|
}
|
|
98
|
-
if (this.#responseCommand
|
|
132
|
+
if (this.#responseCommand?.commandType === CommandType.Exception) {
|
|
99
133
|
throw ExceptionThrower.throwException(this.#responseCommand)
|
|
100
134
|
}
|
|
101
|
-
|
|
102
|
-
if (this.#responseCommand.commandType === CommandType.CreateClassInstance) {
|
|
135
|
+
if (this.#responseCommand?.commandType === CommandType.CreateClassInstance) {
|
|
103
136
|
this.#currentCommand = this.#responseCommand
|
|
104
137
|
this.#isExecuted = true
|
|
105
138
|
return this
|
|
106
139
|
}
|
|
107
|
-
|
|
108
140
|
return new InvocationContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true)
|
|
109
141
|
}
|
|
110
142
|
|
|
@@ -347,7 +379,7 @@ class InvocationContext {
|
|
|
347
379
|
* Creates a null object of a specific type on the target runtime.
|
|
348
380
|
* @param {string} methodName - The name of the method to invoke.
|
|
349
381
|
* @param {...any} args - Method arguments.
|
|
350
|
-
* @returns {InvocationContext} An InvocationContext instance with the command to create a null object.
|
|
382
|
+
* @returns {InvocationContext|InvocationWsContext} An InvocationContext instance with the command to create a null object.
|
|
351
383
|
* TODO: connect documentation page url
|
|
352
384
|
* @see [Javonet Guides](https://www.javonet.com/guides/)
|
|
353
385
|
* @method
|
|
@@ -374,6 +406,10 @@ class InvocationContext {
|
|
|
374
406
|
this.#buildCommand(localCommand)
|
|
375
407
|
)
|
|
376
408
|
localInvCtx.execute()
|
|
409
|
+
|
|
410
|
+
if (localInvCtx.#responseCommand === null) {
|
|
411
|
+
throw new Error('responseCommand is undefined in Invocation Context execute method')
|
|
412
|
+
}
|
|
377
413
|
return localInvCtx.#responseCommand.payload
|
|
378
414
|
}
|
|
379
415
|
|
|
@@ -385,19 +421,30 @@ class InvocationContext {
|
|
|
385
421
|
* @method
|
|
386
422
|
*/
|
|
387
423
|
|
|
424
|
+
/**
|
|
425
|
+
* @returns {unknown}
|
|
426
|
+
*/
|
|
388
427
|
getValue() {
|
|
389
|
-
this.#resultValue = this.#currentCommand
|
|
428
|
+
this.#resultValue = this.#currentCommand?.payload[0]
|
|
390
429
|
return this.#resultValue
|
|
391
430
|
}
|
|
392
431
|
|
|
393
|
-
|
|
432
|
+
/**
|
|
433
|
+
* @param {Command} command
|
|
434
|
+
* @returns {Command}
|
|
435
|
+
*/
|
|
436
|
+
#buildCommand(command) {
|
|
394
437
|
for (let i = 0; i < command.payload.length; i++) {
|
|
395
438
|
command.payload[i] = this.#encapsulatePayloadItem(command.payload[i])
|
|
396
439
|
}
|
|
397
440
|
return command.prependArgToPayload(this.#currentCommand)
|
|
398
441
|
}
|
|
399
442
|
|
|
400
|
-
|
|
443
|
+
/**
|
|
444
|
+
* @param {unknown} payloadItem
|
|
445
|
+
* @returns {Command|null}
|
|
446
|
+
*/
|
|
447
|
+
#encapsulatePayloadItem(payloadItem) {
|
|
401
448
|
// eslint-disable-next-line valid-typeof
|
|
402
449
|
if (payloadItem instanceof Command) {
|
|
403
450
|
for (let i = 0; i < payloadItem.payload.length; i++) {
|
|
@@ -409,7 +456,7 @@ class InvocationContext {
|
|
|
409
456
|
return payloadItem.get_current_command()
|
|
410
457
|
} else if (payloadItem instanceof Array) {
|
|
411
458
|
const copiedArray = payloadItem.map((item) => this.#encapsulatePayloadItem(item))
|
|
412
|
-
return new Command(this
|
|
459
|
+
return new Command(this.#runtimeName, CommandType.Array, copiedArray)
|
|
413
460
|
} else if (typeof payloadItem === 'function') {
|
|
414
461
|
let newArray = new Array(payloadItem.length + 1)
|
|
415
462
|
for (let i = 0; i < newArray.length; i++) {
|
|
@@ -419,23 +466,41 @@ class InvocationContext {
|
|
|
419
466
|
...newArray
|
|
420
467
|
)
|
|
421
468
|
return new Command(this.#runtimeName, CommandType.PassDelegate, args)
|
|
469
|
+
} else if (TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
|
|
470
|
+
return new Command(this.#runtimeName, CommandType.Value, [payloadItem])
|
|
422
471
|
} else {
|
|
423
|
-
|
|
472
|
+
throw Error(
|
|
473
|
+
'Unsupported payload item type: ' +
|
|
474
|
+
(payloadItem?.constructor?.name || typeof payloadItem) +
|
|
475
|
+
' for payload item: ' +
|
|
476
|
+
payloadItem
|
|
477
|
+
)
|
|
424
478
|
}
|
|
425
479
|
}
|
|
426
480
|
}
|
|
427
481
|
|
|
428
482
|
class InvocationWsContext extends InvocationContext {
|
|
483
|
+
/** @type {RuntimeNameType} */
|
|
429
484
|
#runtimeName
|
|
485
|
+
/** @type {IConnectionData} */
|
|
430
486
|
#connectionData
|
|
487
|
+
/** @type {Command | null} */
|
|
431
488
|
#currentCommand
|
|
489
|
+
/** @type {Command | null} */
|
|
432
490
|
#responseCommand
|
|
491
|
+
/** @type {Interpreter | null} */
|
|
433
492
|
#interpreter
|
|
434
|
-
|
|
493
|
+
/** @type {boolean} */
|
|
435
494
|
#isExecuted
|
|
436
|
-
|
|
495
|
+
/** @type {any | null} */
|
|
437
496
|
#resultValue
|
|
438
497
|
|
|
498
|
+
/**
|
|
499
|
+
* @param {RuntimeNameType} runtimeName
|
|
500
|
+
* @param {IConnectionData} connectionData
|
|
501
|
+
* @param {Command} command
|
|
502
|
+
* @param {boolean} isExecuted
|
|
503
|
+
*/
|
|
439
504
|
constructor(runtimeName, connectionData, command, isExecuted = false) {
|
|
440
505
|
super(runtimeName, connectionData, command, isExecuted)
|
|
441
506
|
|
|
@@ -455,11 +520,17 @@ class InvocationWsContext extends InvocationContext {
|
|
|
455
520
|
* Commands are becoming nested through each invocation of methods on Invocation Context.
|
|
456
521
|
* Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
|
|
457
522
|
* 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.
|
|
458
|
-
* @returns {
|
|
523
|
+
* @returns {Promise<InvocationWsContext>} the InvocationContext after executing the command.
|
|
459
524
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
|
|
525
|
+
* @async
|
|
460
526
|
* @method
|
|
461
527
|
*/
|
|
528
|
+
// @ts-expect-error
|
|
462
529
|
async execute() {
|
|
530
|
+
if (this.#currentCommand === null) {
|
|
531
|
+
throw new Error('currentCommand is undefined in Invocation Context execute method')
|
|
532
|
+
}
|
|
533
|
+
|
|
463
534
|
this.#interpreter = new Interpreter()
|
|
464
535
|
this.#responseCommand = await this.#interpreter.executeAsync(
|
|
465
536
|
this.#currentCommand,
|
|
@@ -469,17 +540,14 @@ class InvocationWsContext extends InvocationContext {
|
|
|
469
540
|
if (this.#responseCommand === undefined) {
|
|
470
541
|
throw new Error('responseCommand is undefined in Invocation Context execute method')
|
|
471
542
|
}
|
|
472
|
-
|
|
473
543
|
if (this.#responseCommand.commandType === CommandType.Exception) {
|
|
474
544
|
throw ExceptionThrower.throwException(this.#responseCommand)
|
|
475
545
|
}
|
|
476
|
-
|
|
477
546
|
if (this.#responseCommand.commandType === CommandType.CreateClassInstance) {
|
|
478
547
|
this.#currentCommand = this.#responseCommand
|
|
479
548
|
this.#isExecuted = true
|
|
480
549
|
return this
|
|
481
550
|
}
|
|
482
|
-
|
|
483
551
|
return new InvocationWsContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true)
|
|
484
552
|
}
|
|
485
553
|
}
|
package/lib/sdk/Javonet.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//@ts-check
|
|
1
2
|
import { ConfigRuntimeFactory } from './ConfigRuntimeFactory.js'
|
|
2
3
|
import { RuntimeFactory } from './RuntimeFactory.js'
|
|
3
4
|
import { InMemoryConnectionData } from '../utils/connectionData/InMemoryConnectionData.js'
|
|
@@ -7,10 +8,14 @@ import { CommandDeserializer } from '../core/protocol/CommandDeserializer.js'
|
|
|
7
8
|
import { RuntimeLogger } from '../utils/RuntimeLogger.js'
|
|
8
9
|
import { TcpConnectionData } from '../utils/nodejs/connectionData/TcpConnectionData.js'
|
|
9
10
|
import { WsConnectionData } from '../utils/connectionData/WsConnectionData.js'
|
|
11
|
+
import { ActivationHelper } from './tools/ActivationHelper.js'
|
|
12
|
+
import { UtilsConst } from '../utils/UtilsConst.js'
|
|
13
|
+
|
|
14
|
+
/** @typedef {import('../types.d.ts').ConfigSource} ConfigSource */
|
|
10
15
|
|
|
11
16
|
const requireDynamic = getRequire(import.meta.url)
|
|
12
17
|
|
|
13
|
-
/** @type {import('../core/transmitter/Transmitter') | null} */
|
|
18
|
+
/** @type {typeof import('../core/transmitter/Transmitter.js').Transmitter | null} */
|
|
14
19
|
let _Transmitter = null
|
|
15
20
|
|
|
16
21
|
if (isNodejsRuntime()) {
|
|
@@ -64,28 +69,28 @@ class Javonet {
|
|
|
64
69
|
/**
|
|
65
70
|
* Initializes Javonet with a custom configuration file taken from external source.
|
|
66
71
|
* Currentyl supported: Configuration file in JSON format
|
|
67
|
-
* @param config - Path to a configuration file.
|
|
72
|
+
* @param {string|ConfigSource} config - Path to a configuration file.
|
|
68
73
|
* @returns {ConfigRuntimeFactory} A ConfigRuntimeFactory instance with configuration data.
|
|
69
74
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/configure-channel)
|
|
70
75
|
*/
|
|
71
76
|
static withConfig(config) {
|
|
72
|
-
return new ConfigRuntimeFactory(config
|
|
77
|
+
return new ConfigRuntimeFactory(config)
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
81
|
* Activates Javonet with the provided license key.
|
|
77
82
|
* @param {string} licenseKey - The license key to activate Javonet.
|
|
78
|
-
* @returns {
|
|
83
|
+
* @returns {void} The activation status code.
|
|
79
84
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/getting-started/activating-javonet)
|
|
80
85
|
*/
|
|
81
86
|
static activate(licenseKey) {
|
|
82
|
-
|
|
83
|
-
return _Transmitter?.activate(licenseKey)
|
|
84
|
-
} else {
|
|
85
|
-
throw new Error('Javonet.activate is allowed only to run in nodejs runtime')
|
|
86
|
-
}
|
|
87
|
+
UtilsConst.setLicenseKey(licenseKey)
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Gets the runtime information.
|
|
92
|
+
* @returns {string} The runtime information.
|
|
93
|
+
*/
|
|
89
94
|
static getRuntimeInfo() {
|
|
90
95
|
if (isNodejsRuntime()) {
|
|
91
96
|
return RuntimeLogger.getRuntimeInfo()
|
|
@@ -96,43 +101,20 @@ class Javonet {
|
|
|
96
101
|
|
|
97
102
|
/**
|
|
98
103
|
* Sets the configuration source for the Javonet SDK.
|
|
99
|
-
*
|
|
100
104
|
* @param {string} configSource - The configuration source.
|
|
105
|
+
* @returns {void}
|
|
101
106
|
*/
|
|
102
107
|
static setConfigSource(configSource) {
|
|
103
|
-
|
|
104
|
-
return _Transmitter?.setConfigSource(configSource)
|
|
105
|
-
} else {
|
|
106
|
-
throw new Error('Javonet.setConfigSource is allowed only to run in nodejs runtime')
|
|
107
|
-
}
|
|
108
|
+
UtilsConst.setConfigSource(configSource)
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
112
|
* Sets the working directory for the Javonet SDK.
|
|
112
|
-
*
|
|
113
113
|
* @param {string} path - The working directory.
|
|
114
|
+
* @returns {void}
|
|
114
115
|
*/
|
|
115
116
|
static setJavonetWorkingDirectory(path) {
|
|
116
|
-
|
|
117
|
-
if (isNodejsRuntime()) {
|
|
118
|
-
const { mkdirSync } = requireDynamic('fs')
|
|
119
|
-
|
|
120
|
-
path = path.replace(/\\/g, '/')
|
|
121
|
-
if (!path.endsWith('/')) {
|
|
122
|
-
path += '/'
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
mkdirSync(path, { recursive: true, mode: 0o700 })
|
|
126
|
-
_Transmitter?.setJavonetWorkingDirectory(path)
|
|
127
|
-
} else {
|
|
128
|
-
throw new Error('Javonet.setJavonetWorkingDirectory is allowed only to run in nodejs runtime')
|
|
129
|
-
}
|
|
130
|
-
} catch (error) {
|
|
131
|
-
if (error.code === 'MODULE_NOT_FOUND') {
|
|
132
|
-
throw new Error('fs module not found. Please install it using npm install fs')
|
|
133
|
-
}
|
|
134
|
-
throw error
|
|
135
|
-
}
|
|
117
|
+
UtilsConst.setJavonetWorkingDirectory(path)
|
|
136
118
|
}
|
|
137
119
|
}
|
|
138
120
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
2
|
import { Command } from '../utils/Command.js'
|
|
3
3
|
import { CommandType } from '../utils/CommandType.js'
|
|
4
4
|
import { InvocationContext, InvocationWsContext } from './InvocationContext.js'
|
|
@@ -7,6 +7,20 @@ import { ExceptionThrower } from '../utils/exception/ExceptionThrower.js'
|
|
|
7
7
|
import { RuntimeName } from '../utils/RuntimeName.js'
|
|
8
8
|
import { Interpreter } from '../core/interpreter/Interpreter.js'
|
|
9
9
|
import { delegatesCacheInstance } from '../core/delegatesCache/DelegatesCache.js'
|
|
10
|
+
import { TypesHandler } from '../utils/TypesHandler.js'
|
|
11
|
+
import { UtilsConst } from '../utils/UtilsConst.js'
|
|
12
|
+
import { getRequire } from '../utils/Runtime.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import('../types.d.ts').RuntimeName} RuntimeNameType
|
|
16
|
+
* @typedef {import('../utils/connectionData/IConnectionData.js').IConnectionData} IConnectionData
|
|
17
|
+
* @typedef {typeof import('../core/transmitter/Transmitter.js').Transmitter} Transmitter
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** @type {typeof import('../core/transmitter/Transmitter.js').Transmitter | null} */
|
|
21
|
+
let _Transmitter = null
|
|
22
|
+
|
|
23
|
+
const requireDynamic = getRequire(import.meta.url)
|
|
10
24
|
|
|
11
25
|
/**
|
|
12
26
|
* Represents a single context which allows interaction with a selected technology.
|
|
@@ -20,54 +34,93 @@ import { delegatesCacheInstance } from '../core/delegatesCache/DelegatesCache.js
|
|
|
20
34
|
* @class
|
|
21
35
|
*/
|
|
22
36
|
class RuntimeContext {
|
|
37
|
+
/** @type {Map<string, RuntimeContext>} */
|
|
23
38
|
static memoryRuntimeContexts = new Map()
|
|
39
|
+
/** @type {Map<string, RuntimeContext>} */
|
|
24
40
|
static networkRuntimeContexts = new Map()
|
|
41
|
+
/** @type {Map<string, RuntimeContext>} */
|
|
25
42
|
static webSocketRuntimeContexts = new Map()
|
|
26
|
-
#currentCommand
|
|
27
|
-
#responseCommand
|
|
28
|
-
#interpreter
|
|
29
43
|
|
|
44
|
+
/** @type {Command | null} */
|
|
45
|
+
#currentCommand = null
|
|
46
|
+
/** @type {Command | null} */
|
|
47
|
+
#responseCommand = null
|
|
48
|
+
/** @type {Interpreter | null} */
|
|
49
|
+
#interpreter = null
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {RuntimeNameType} runtimeName
|
|
53
|
+
* @param {IConnectionData} connectionData
|
|
54
|
+
*/
|
|
30
55
|
constructor(runtimeName, connectionData) {
|
|
56
|
+
this._isExecuted = false
|
|
31
57
|
this.runtimeName = runtimeName
|
|
32
58
|
this.connectionData = connectionData
|
|
33
|
-
this.#currentCommand = null
|
|
34
|
-
this.#responseCommand = null
|
|
35
59
|
this.#interpreter = new Interpreter()
|
|
60
|
+
|
|
61
|
+
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
if (
|
|
65
|
+
this.runtimeName === RuntimeName.Nodejs &&
|
|
66
|
+
this.connectionData.connectionType === ConnectionType.IN_MEMORY
|
|
67
|
+
) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_Transmitter?.setJavonetWorkingDirectory(UtilsConst.getJavonetWorkingDirectory())
|
|
72
|
+
if (UtilsConst.getConfigSource() !== '') {
|
|
73
|
+
_Transmitter?.setConfigSource(UtilsConst.getConfigSource())
|
|
74
|
+
}
|
|
75
|
+
_Transmitter?.activate(UtilsConst.getLicenseKey())
|
|
36
76
|
}
|
|
37
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @param {RuntimeNameType} runtimeName
|
|
80
|
+
* @param {IConnectionData} connectionData
|
|
81
|
+
* @returns {RuntimeContext}
|
|
82
|
+
*/
|
|
38
83
|
static getInstance(runtimeName, connectionData) {
|
|
84
|
+
if (!_Transmitter) {
|
|
85
|
+
const { Transmitter } = requireDynamic('../core/transmitter/Transmitter.js')
|
|
86
|
+
_Transmitter = Transmitter
|
|
87
|
+
}
|
|
39
88
|
switch (connectionData.connectionType) {
|
|
40
89
|
case ConnectionType.IN_MEMORY:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
runtimeCtx
|
|
90
|
+
const key = String(runtimeName)
|
|
91
|
+
if (RuntimeContext.memoryRuntimeContexts.has(key)) {
|
|
92
|
+
const runtimeCtx = RuntimeContext.memoryRuntimeContexts.get(key)
|
|
93
|
+
if (!runtimeCtx) throw new Error('Runtime context not found')
|
|
94
|
+
runtimeCtx.#currentCommand = null
|
|
44
95
|
return runtimeCtx
|
|
45
96
|
} else {
|
|
46
|
-
|
|
47
|
-
RuntimeContext.memoryRuntimeContexts
|
|
97
|
+
const runtimeCtx = new RuntimeContext(runtimeName, connectionData)
|
|
98
|
+
RuntimeContext.memoryRuntimeContexts.set(key, runtimeCtx)
|
|
48
99
|
return runtimeCtx
|
|
49
100
|
}
|
|
50
101
|
case ConnectionType.TCP: {
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
runtimeCtx
|
|
102
|
+
const key1 = String(runtimeName) + JSON.stringify(connectionData)
|
|
103
|
+
if (RuntimeContext.networkRuntimeContexts.has(key1)) {
|
|
104
|
+
const runtimeCtx = RuntimeContext.networkRuntimeContexts.get(key1)
|
|
105
|
+
if (!runtimeCtx) throw new Error('Runtime context not found')
|
|
106
|
+
runtimeCtx.#currentCommand = null
|
|
55
107
|
return runtimeCtx
|
|
56
108
|
} else {
|
|
57
|
-
|
|
58
|
-
RuntimeContext.networkRuntimeContexts
|
|
109
|
+
const runtimeCtx = new RuntimeContext(runtimeName, connectionData)
|
|
110
|
+
RuntimeContext.networkRuntimeContexts.set(key1, runtimeCtx)
|
|
59
111
|
return runtimeCtx
|
|
60
112
|
}
|
|
61
113
|
}
|
|
62
114
|
case ConnectionType.WEB_SOCKET: {
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
runtimeCtx
|
|
115
|
+
const key2 = String(runtimeName) + JSON.stringify(connectionData)
|
|
116
|
+
if (RuntimeContext.webSocketRuntimeContexts.has(key2)) {
|
|
117
|
+
const runtimeCtx = RuntimeContext.webSocketRuntimeContexts.get(key2)
|
|
118
|
+
if (!runtimeCtx) throw new Error('Runtime context not found')
|
|
119
|
+
runtimeCtx.#currentCommand = null
|
|
67
120
|
return runtimeCtx
|
|
68
121
|
} else {
|
|
69
|
-
|
|
70
|
-
RuntimeContext.webSocketRuntimeContexts
|
|
122
|
+
const runtimeCtx = new RuntimeContext(runtimeName, connectionData)
|
|
123
|
+
RuntimeContext.webSocketRuntimeContexts.set(key2, runtimeCtx)
|
|
71
124
|
return runtimeCtx
|
|
72
125
|
}
|
|
73
126
|
}
|
|
@@ -86,12 +139,13 @@ class RuntimeContext {
|
|
|
86
139
|
* @method
|
|
87
140
|
*/
|
|
88
141
|
execute() {
|
|
89
|
-
|
|
142
|
+
// @ts-expect-error
|
|
143
|
+
this.#responseCommand = this.#interpreter?.execute(this.#currentCommand, this.connectionData)
|
|
90
144
|
this.#currentCommand = null
|
|
91
145
|
if (this.#responseCommand === undefined) {
|
|
92
146
|
throw new Error('responseCommand is undefined in Runtime Context execute method')
|
|
93
147
|
}
|
|
94
|
-
if (this.#responseCommand
|
|
148
|
+
if (this.#responseCommand?.commandType === CommandType.Exception) {
|
|
95
149
|
throw ExceptionThrower.throwException(this.#responseCommand)
|
|
96
150
|
}
|
|
97
151
|
}
|
|
@@ -124,6 +178,7 @@ class RuntimeContext {
|
|
|
124
178
|
let localCommand = new Command(this.runtimeName, CommandType.GetType, [typeName, ...args])
|
|
125
179
|
this.#currentCommand = null
|
|
126
180
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
181
|
+
// @ts-expect-error
|
|
127
182
|
return new InvocationWsContext(
|
|
128
183
|
this.runtimeName,
|
|
129
184
|
this.connectionData,
|
|
@@ -146,6 +201,7 @@ class RuntimeContext {
|
|
|
146
201
|
let localCommand = new Command(this.runtimeName, CommandType.Cast, args)
|
|
147
202
|
this.#currentCommand = null
|
|
148
203
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
204
|
+
// @ts-expect-error
|
|
149
205
|
return new InvocationWsContext(
|
|
150
206
|
this.runtimeName,
|
|
151
207
|
this.connectionData,
|
|
@@ -168,6 +224,7 @@ class RuntimeContext {
|
|
|
168
224
|
let localCommand = new Command(this.runtimeName, CommandType.GetEnumItem, args)
|
|
169
225
|
this.#currentCommand = null
|
|
170
226
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
227
|
+
// @ts-expect-error
|
|
171
228
|
return new InvocationWsContext(
|
|
172
229
|
this.runtimeName,
|
|
173
230
|
this.connectionData,
|
|
@@ -190,6 +247,7 @@ class RuntimeContext {
|
|
|
190
247
|
let localCommand = new Command(this.runtimeName, CommandType.AsRef, args)
|
|
191
248
|
this.#currentCommand = null
|
|
192
249
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
250
|
+
// @ts-expect-error
|
|
193
251
|
return new InvocationWsContext(
|
|
194
252
|
this.runtimeName,
|
|
195
253
|
this.connectionData,
|
|
@@ -212,6 +270,7 @@ class RuntimeContext {
|
|
|
212
270
|
let localCommand = new Command(this.runtimeName, CommandType.AsOut, args)
|
|
213
271
|
this.#currentCommand = null
|
|
214
272
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
273
|
+
// @ts-expect-error
|
|
215
274
|
return new InvocationWsContext(
|
|
216
275
|
this.runtimeName,
|
|
217
276
|
this.connectionData,
|
|
@@ -238,6 +297,7 @@ class RuntimeContext {
|
|
|
238
297
|
])
|
|
239
298
|
this.#currentCommand = null
|
|
240
299
|
if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
|
|
300
|
+
// @ts-expect-error
|
|
241
301
|
return new InvocationWsContext(
|
|
242
302
|
this.runtimeName,
|
|
243
303
|
this.connectionData,
|
|
@@ -247,22 +307,35 @@ class RuntimeContext {
|
|
|
247
307
|
return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
|
|
248
308
|
}
|
|
249
309
|
|
|
250
|
-
|
|
310
|
+
/**
|
|
311
|
+
* @param {Command} command
|
|
312
|
+
* @returns {Command}
|
|
313
|
+
*/
|
|
314
|
+
#buildCommand(command) {
|
|
251
315
|
for (let i = 0; i < command.payload.length; i++) {
|
|
252
316
|
command.payload[i] = this.#encapsulatePayloadItem(command.payload[i])
|
|
253
317
|
}
|
|
254
318
|
return command.prependArgToPayload(this.#currentCommand)
|
|
255
319
|
}
|
|
256
320
|
|
|
257
|
-
|
|
321
|
+
/**
|
|
322
|
+
* @param {unknown} payloadItem
|
|
323
|
+
* @returns {Command}
|
|
324
|
+
*/
|
|
325
|
+
#encapsulatePayloadItem(payloadItem) {
|
|
258
326
|
if (payloadItem instanceof Command) {
|
|
259
327
|
for (let i = 0; i < payloadItem.payload.length; i++) {
|
|
260
328
|
payloadItem.payload[i] = this.#encapsulatePayloadItem(payloadItem.payload[i])
|
|
261
329
|
}
|
|
262
330
|
return payloadItem
|
|
263
331
|
} else if (payloadItem instanceof InvocationContext) {
|
|
264
|
-
|
|
332
|
+
const command = payloadItem?.get_current_command()
|
|
333
|
+
if (!command) {
|
|
334
|
+
throw new Error('Command not found')
|
|
335
|
+
}
|
|
336
|
+
return command
|
|
265
337
|
} else if (payloadItem instanceof Array) {
|
|
338
|
+
/** @type {Command[]} */
|
|
266
339
|
const copiedArray = payloadItem.map((item) => this.#encapsulatePayloadItem(item))
|
|
267
340
|
return new Command(this.runtimeName, CommandType.Array, copiedArray)
|
|
268
341
|
} else if (typeof payloadItem === 'function') {
|
|
@@ -274,8 +347,15 @@ class RuntimeContext {
|
|
|
274
347
|
...newArray
|
|
275
348
|
)
|
|
276
349
|
return new Command(this.runtimeName, CommandType.PassDelegate, args)
|
|
277
|
-
} else {
|
|
350
|
+
} else if (TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
|
|
278
351
|
return new Command(this.runtimeName, CommandType.Value, [payloadItem])
|
|
352
|
+
} else {
|
|
353
|
+
throw Error(
|
|
354
|
+
'Unsupported payload item type: ' +
|
|
355
|
+
(payloadItem?.constructor?.name || typeof payloadItem) +
|
|
356
|
+
' for payload item: ' +
|
|
357
|
+
payloadItem
|
|
358
|
+
)
|
|
279
359
|
}
|
|
280
360
|
}
|
|
281
361
|
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
//@ts-check
|
|
1
2
|
import { RuntimeName } from '../utils/RuntimeName.js'
|
|
2
3
|
import { RuntimeContext } from './RuntimeContext.js'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('../utils/connectionData/IConnectionData.js').IConnectionData} IConnectionData
|
|
7
|
+
*/
|
|
4
8
|
/**
|
|
5
9
|
* The RuntimeFactory class provides methods for creating runtime contexts.
|
|
6
10
|
* Each method corresponds to a specific runtime (CLR, JVM, .NET Core, Perl, Ruby, Node.js, Python) and returns a RuntimeContext instance for that runtime.
|
|
7
11
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
|
|
8
12
|
*/
|
|
9
13
|
export class RuntimeFactory {
|
|
14
|
+
/**
|
|
15
|
+
* @param {IConnectionData} connectionData
|
|
16
|
+
*/
|
|
10
17
|
constructor(connectionData) {
|
|
11
18
|
this.connectionData = connectionData
|
|
12
19
|
}
|