javonet-nodejs-sdk 2.6.6 → 2.6.7

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.
@@ -23,10 +23,10 @@ __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");
28
26
  const import_meta = {};
29
- const dynamicImport = (0, import_Runtime.getRequire)(import_meta.url);
27
+ let _existsSync = null;
28
+ let _resolve = null;
29
+ const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
30
30
  class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
31
31
  requiredParametersCount = 1;
32
32
  /** @type {string[]} */
@@ -46,8 +46,16 @@ class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
46
46
  if (!lib) {
47
47
  throw new Error("Cannot load module: Library path is required but was not provided");
48
48
  }
49
- const absolutePath = (0, import_path.resolve)(lib);
50
- if (!(0, import_fs.existsSync)(lib) && !(0, import_fs.existsSync)(absolutePath)) {
49
+ if (!_existsSync) {
50
+ const { existsSync } = requireDynamic("fs");
51
+ _existsSync = existsSync;
52
+ }
53
+ if (!_resolve) {
54
+ const { resolve } = requireDynamic("path");
55
+ _resolve = resolve;
56
+ }
57
+ const absolutePath = _resolve?.(lib);
58
+ if (!_existsSync?.(lib ?? "") && !_existsSync?.(absolutePath ?? "")) {
51
59
  throw new Error(`Cannot load module: Library not found: ${lib}`);
52
60
  }
53
61
  let pathArray = lib.split(/[/\\]/);
@@ -55,7 +63,7 @@ class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
55
63
  libraryName = libraryName.replace(".js", "");
56
64
  let moduleExports;
57
65
  try {
58
- moduleExports = dynamicImport(lib);
66
+ moduleExports = requireDynamic(lib);
59
67
  LoadLibraryHandler.loadedLibraries.push(lib);
60
68
  } catch (error) {
61
69
  throw Error("Cannot load module: " + lib + "\n" + error);
@@ -32,10 +32,7 @@ var import_Handler = require("../handler/Handler.cjs");
32
32
  const import_meta = {};
33
33
  let _Receiver;
34
34
  let _Transmitter;
35
- let _TransmitterWebsocket = null;
36
- if (!_TransmitterWebsocket) {
37
- _TransmitterWebsocket = (0, import_Runtime.isNodejsRuntime)() ? import_TransmitterWebsocket.TransmitterWebsocket : import_TransmitterWebsocketBrowser.TransmitterWebsocketBrowser;
38
- }
35
+ let _TransmitterWebsocket = (0, import_Runtime.isNodejsRuntime)() ? import_TransmitterWebsocket.TransmitterWebsocket : import_TransmitterWebsocketBrowser.TransmitterWebsocketBrowser;
39
36
  const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
40
37
  class Interpreter {
41
38
  /** @type {Handler | null} */
@@ -51,106 +48,66 @@ class Interpreter {
51
48
  *
52
49
  * @param {Command} command
53
50
  * @param {IConnectionData} connectionData
54
- * @returns
51
+ * @returns {Command | Promise<Command>}
55
52
  */
56
- async executeAsync(command, connectionData) {
53
+ execute(command, connectionData) {
57
54
  try {
58
55
  let messageByteArray = new import_CommandSerializer.CommandSerializer().serialize(command, connectionData);
56
+ if (!(messageByteArray instanceof Uint8Array) && !(messageByteArray instanceof Promise)) {
57
+ throw new Error("Serialized message is neither Uint8Array nor Promise<Uint8Array>");
58
+ }
59
59
  let responseByteArray = void 0;
60
- if (connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
61
- const _response = await _TransmitterWebsocket?.sendCommand(
62
- await messageByteArray,
63
- connectionData
64
- );
65
- if (_response) {
66
- const command2 = new import_CommandDeserializer.CommandDeserializer(_response).deserialize();
67
- return command2;
68
- } else {
69
- throw new Error("Response not received from TransmitterWebsocket");
60
+ if (!(0, import_Runtime.isNodejsRuntime)() && connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
61
+ throw new Error("Nodejs Core Error: inMemory is only allowed in Nodejs runtime, not in browser");
62
+ }
63
+ if (command.runtimeName === import_RuntimeName.RuntimeName.Nodejs && connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
64
+ if (!_Receiver) {
65
+ const { Receiver } = require("../receiver/Receiver.cjs");
66
+ _Receiver = Receiver;
70
67
  }
71
- } else {
72
- if (!(0, import_Runtime.isNodejsRuntime)()) {
73
- throw new Error("InMemory is only allowed in Nodejs runtime");
68
+ if (!_Receiver) {
69
+ throw new Error("Nodejs Core Error: Receiver is undefined");
70
+ }
71
+ if (messageByteArray instanceof Promise) {
72
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
73
+ return _Receiver.sendCommand(resolvedMessage);
74
+ });
75
+ } else if (messageByteArray instanceof Uint8Array) {
76
+ responseByteArray = _Receiver.sendCommand(messageByteArray);
74
77
  }
75
- if (command.runtimeName === import_RuntimeName.RuntimeName.Nodejs) {
76
- if (!_Receiver) {
77
- const { Receiver } = require("../receiver/Receiver.cjs");
78
- _Receiver = Receiver;
79
- }
80
- responseByteArray = await _Receiver?.sendCommand(await messageByteArray);
78
+ } else if (connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY || connectionData.connectionType === import_ConnectionType.ConnectionType.TCP) {
79
+ if (!_Transmitter) {
80
+ const { Transmitter } = require("../transmitter/Transmitter.cjs");
81
+ _Transmitter = Transmitter;
82
+ }
83
+ if (!_Transmitter) {
84
+ throw new Error("Nodejs Core Error: Transmitter is undefined");
85
+ }
86
+ if (messageByteArray instanceof Uint8Array) {
87
+ responseByteArray = _Transmitter.sendCommand(messageByteArray);
81
88
  } else {
82
- if (!_Transmitter) {
83
- const { Transmitter } = require("../transmitter/Transmitter.cjs");
84
- _Transmitter = Transmitter;
85
- }
86
- responseByteArray = await _Transmitter?.sendCommand(await messageByteArray);
89
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
90
+ return _Transmitter.sendCommand(resolvedMessage);
91
+ });
92
+ }
93
+ } else if (connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
94
+ if (messageByteArray instanceof Uint8Array) {
95
+ responseByteArray = _TransmitterWebsocket.sendCommand(messageByteArray, connectionData);
96
+ } else {
97
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
98
+ return _TransmitterWebsocket.sendCommand(resolvedMessage, connectionData);
99
+ });
87
100
  }
88
101
  }
89
102
  if (!responseByteArray) {
90
103
  throw new Error("No response received from Transmitter");
91
104
  }
92
- return new import_CommandDeserializer.CommandDeserializer(responseByteArray).deserialize();
93
- } catch (error) {
94
- throw error;
95
- }
96
- }
97
- /**
98
- *
99
- * @param {Command} command
100
- * @param {IConnectionData} connectionData
101
- * @returns {Command | Promise<Command>}
102
- */
103
- execute(command, connectionData) {
104
- try {
105
- let messageByteArray = new import_CommandSerializer.CommandSerializer().serialize(command, connectionData);
106
- let responseByteArray = void 0;
107
- if (connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
108
- throw new Error("Not supported");
105
+ if (responseByteArray instanceof Promise) {
106
+ return responseByteArray.then((resolvedResponse) => {
107
+ return new import_CommandDeserializer.CommandDeserializer(resolvedResponse).deserialize();
108
+ });
109
109
  } else {
110
- if (!(0, import_Runtime.isNodejsRuntime)()) {
111
- throw new Error("InMemory is only allowed in Nodejs runtime");
112
- }
113
- if (command.runtimeName === import_RuntimeName.RuntimeName.Nodejs && connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
114
- if (!_Receiver) {
115
- const { Receiver } = require("../receiver/Receiver.cjs");
116
- _Receiver = Receiver;
117
- }
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
- }
128
- } else {
129
- if (!_Transmitter) {
130
- const { Transmitter } = require("../transmitter/Transmitter.cjs");
131
- _Transmitter = Transmitter;
132
- }
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();
153
- }
110
+ return new import_CommandDeserializer.CommandDeserializer(responseByteArray).deserialize();
154
111
  }
155
112
  } catch (error) {
156
113
  throw error;
@@ -18,8 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var InvocationContext_exports = {};
20
20
  __export(InvocationContext_exports, {
21
- InvocationContext: () => InvocationContext,
22
- InvocationWsContext: () => InvocationWsContext
21
+ InvocationContext: () => InvocationContext
23
22
  });
24
23
  module.exports = __toCommonJS(InvocationContext_exports);
25
24
  var import_DelegatesCache = require("../core/delegatesCache/DelegatesCache.cjs");
@@ -63,13 +62,6 @@ class InvocationContext {
63
62
  * @returns {InvocationContext}
64
63
  */
65
64
  #createInstanceContext(localCommand) {
66
- if (this.#connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
67
- return new InvocationWsContext(
68
- this.#runtimeName,
69
- this.#connectionData,
70
- this.#buildCommand(localCommand)
71
- );
72
- }
73
65
  return new InvocationContext(
74
66
  this.#runtimeName,
75
67
  this.#connectionData,
@@ -376,7 +368,7 @@ class InvocationContext {
376
368
  * Creates a null object of a specific type on the target runtime.
377
369
  * @param {string} methodName - The name of the method to invoke.
378
370
  * @param {...any} args - Method arguments.
379
- * @returns {InvocationContext|InvocationWsContext} An InvocationContext instance with the command to create a null object.
371
+ * @returns {InvocationContext} An InvocationContext instance with the command to create a null object.
380
372
  * TODO: connect documentation page url
381
373
  * @see [Javonet Guides](https://www.javonet.com/guides/)
382
374
  * @method
@@ -401,15 +393,10 @@ class InvocationContext {
401
393
  this.#connectionData,
402
394
  this.#buildCommand(localCommand)
403
395
  );
404
- const execCtx = (
405
- /** @type {any} */
406
- invocationContext.execute()
407
- );
408
- const result = execCtx.getValue();
409
- return (
410
- /** @type {string} */
411
- result
412
- );
396
+ const execCtx = invocationContext.execute();
397
+ const extract = (invCtx) => String(invCtx.getValue());
398
+ console.log(execCtx);
399
+ return execCtx instanceof Promise ? execCtx.then(extract) : extract(execCtx);
413
400
  }
414
401
  /**
415
402
  * Retrieves the name of the runtime where the command is executed.
@@ -491,135 +478,7 @@ class InvocationContext {
491
478
  }
492
479
  }
493
480
  }
494
- class InvocationWsContext extends InvocationContext {
495
- /** @type {RuntimeNameType} */
496
- #runtimeName;
497
- /** @type {IConnectionData} */
498
- #connectionData;
499
- /** @type {Command | null} */
500
- #currentCommand;
501
- /** @type {Command | null} */
502
- #responseCommand;
503
- /** @type {Interpreter | null} */
504
- #interpreter;
505
- /** @type {boolean} */
506
- #isExecuted;
507
- /**
508
- * @param {RuntimeNameType} runtimeName
509
- * @param {IConnectionData} connectionData
510
- * @param {Command} command
511
- * @param {boolean} isExecuted
512
- */
513
- constructor(runtimeName, connectionData, command, isExecuted = false) {
514
- super(runtimeName, connectionData, command, isExecuted);
515
- this.#runtimeName = runtimeName;
516
- this.#connectionData = connectionData;
517
- this.#currentCommand = command;
518
- this.#responseCommand = null;
519
- this.#isExecuted = isExecuted;
520
- this.#interpreter = null;
521
- }
522
- /**
523
- * Executes the current command.
524
- * Because invocation context is building the intent of executing particular expression on target environment, we call the initial state of invocation context as non-materialized.
525
- * The non-materialized context wraps either single command or chain of recursively nested commands.
526
- * Commands are becoming nested through each invocation of methods on Invocation Context.
527
- * Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
528
- * 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.
529
- * @returns {Promise<InvocationWsContext>} the InvocationContext after executing the command.
530
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
531
- * @async
532
- * @method
533
- */
534
- async execute() {
535
- if (this.#currentCommand === null) {
536
- throw new Error("currentCommand is undefined in Invocation Context execute method");
537
- }
538
- if (!this.#interpreter) {
539
- this.#interpreter = new import_Interpreter.Interpreter();
540
- }
541
- this.#responseCommand = await this.#interpreter.executeAsync(
542
- this.#currentCommand,
543
- this.#connectionData
544
- );
545
- if (this.#responseCommand === void 0) {
546
- throw new Error("responseCommand is undefined in Invocation Context execute method");
547
- }
548
- if (this.#responseCommand.commandType === import_CommandType.CommandType.Exception) {
549
- throw import_ExceptionThrower.ExceptionThrower.throwException(this.#responseCommand);
550
- }
551
- if (this.#responseCommand.commandType === import_CommandType.CommandType.CreateClassInstance) {
552
- this.#currentCommand = this.#responseCommand;
553
- this.#isExecuted = true;
554
- return this;
555
- }
556
- return new InvocationWsContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true);
557
- }
558
- /**
559
- * Retrieves the type of the object from the target runtime.
560
- * @returns {Promise<string>} The type of the object.
561
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
562
- * @async
563
- * @method
564
- */
565
- async getResultType() {
566
- const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
567
- const invocationContext = new InvocationWsContext(
568
- this.#runtimeName,
569
- this.#connectionData,
570
- this.#buildCommand(localCommand)
571
- );
572
- const result = await invocationContext.execute();
573
- return (
574
- /** @type {string} */
575
- result.getValue()
576
- );
577
- }
578
- /**
579
- * @param {Command} command
580
- * @returns {Command}
581
- */
582
- #buildCommand(command) {
583
- for (let i = 0; i < command.payload.length; i++) {
584
- command.payload[i] = this.#encapsulatePayloadItem(command.payload[i]);
585
- }
586
- return command.prependArgToPayload(this.#currentCommand);
587
- }
588
- /**
589
- * @param {unknown} payloadItem
590
- * @returns {Command|null}
591
- */
592
- #encapsulatePayloadItem(payloadItem) {
593
- if (payloadItem instanceof import_Command.Command) {
594
- for (let i = 0; i < payloadItem.payload.length; i++) {
595
- payloadItem.payload[i] = this.#encapsulatePayloadItem(payloadItem.payload[i]);
596
- }
597
- return payloadItem;
598
- } else if (payloadItem instanceof InvocationContext || payloadItem instanceof InvocationWsContext) {
599
- return payloadItem.get_current_command();
600
- } else if (payloadItem instanceof Array) {
601
- const copiedArray = payloadItem.map((item) => this.#encapsulatePayloadItem(item));
602
- return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.Array, copiedArray);
603
- } else if (typeof payloadItem === "function") {
604
- let newArray = new Array(payloadItem.length + 1);
605
- for (let i = 0; i < newArray.length; i++) {
606
- newArray[i] = typeof Object;
607
- }
608
- const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs].push(
609
- ...newArray
610
- );
611
- return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.PassDelegate, args);
612
- } else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
613
- return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.Value, [payloadItem]);
614
- } else {
615
- throw Error(
616
- "Unsupported payload item type: " + (payloadItem?.constructor?.name || typeof payloadItem) + " for payload item: " + payloadItem
617
- );
618
- }
619
- }
620
- }
621
481
  // Annotate the CommonJS export names for ESM import in node:
622
482
  0 && (module.exports = {
623
- InvocationContext,
624
- InvocationWsContext
483
+ InvocationContext
625
484
  });
@@ -39,17 +39,6 @@ var import_WsConnectionData = require("../utils/connectionData/WsConnectionData.
39
39
  var import_UtilsConst = require("../utils/UtilsConst.cjs");
40
40
  var import_ConfigSourceResolver = require("./configuration/ConfigSourceResolver.cjs");
41
41
  var import_ConfigPriority = require("./configuration/ConfigPriority.cjs");
42
- const import_meta = {};
43
- const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
44
- let _Transmitter = null;
45
- if ((0, import_Runtime.isNodejsRuntime)()) {
46
- try {
47
- const { Transmitter } = require("../core/transmitter/Transmitter.cjs");
48
- _Transmitter = Transmitter;
49
- } catch (error) {
50
- throw error;
51
- }
52
- }
53
42
  class Javonet {
54
43
  /**
55
44
  * Initializes Javonet using an in-memory channel on the same machine.
@@ -75,6 +75,9 @@ class RuntimeContext {
75
75
  * @returns {RuntimeContext}
76
76
  */
77
77
  static getInstance(runtimeName, connectionData) {
78
+ if (!(0, import_Runtime.isNodejsRuntime)() && connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
79
+ throw new Error("Nodejs Core Error: inMemory is only allowed in Nodejs runtime, not in browser");
80
+ }
78
81
  switch (connectionData.connectionType) {
79
82
  case import_ConnectionType.ConnectionType.IN_MEMORY:
80
83
  const key = String(runtimeName);
@@ -171,13 +174,6 @@ class RuntimeContext {
171
174
  getType(typeName, ...args) {
172
175
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.GetType, [typeName, ...args]);
173
176
  this.#currentCommand = null;
174
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
175
- return new import_InvocationContext.InvocationWsContext(
176
- this.runtimeName,
177
- this.connectionData,
178
- this.#buildCommand(localCommand)
179
- );
180
- }
181
177
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
182
178
  }
183
179
  /**
@@ -192,13 +188,6 @@ class RuntimeContext {
192
188
  cast(...args) {
193
189
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.Cast, args);
194
190
  this.#currentCommand = null;
195
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
196
- return new import_InvocationContext.InvocationWsContext(
197
- this.runtimeName,
198
- this.connectionData,
199
- this.#buildCommand(localCommand)
200
- );
201
- }
202
191
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
203
192
  }
204
193
  /**
@@ -213,13 +202,6 @@ class RuntimeContext {
213
202
  getEnumItem(...args) {
214
203
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.GetEnumItem, args);
215
204
  this.#currentCommand = null;
216
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
217
- return new import_InvocationContext.InvocationWsContext(
218
- this.runtimeName,
219
- this.connectionData,
220
- this.#buildCommand(localCommand)
221
- );
222
- }
223
205
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
224
206
  }
225
207
  /**
@@ -234,13 +216,6 @@ class RuntimeContext {
234
216
  asRef(...args) {
235
217
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.AsRef, args);
236
218
  this.#currentCommand = null;
237
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
238
- return new import_InvocationContext.InvocationWsContext(
239
- this.runtimeName,
240
- this.connectionData,
241
- this.#buildCommand(localCommand)
242
- );
243
- }
244
219
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
245
220
  }
246
221
  /**
@@ -255,13 +230,6 @@ class RuntimeContext {
255
230
  asOut(...args) {
256
231
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.AsOut, args);
257
232
  this.#currentCommand = null;
258
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
259
- return new import_InvocationContext.InvocationWsContext(
260
- this.runtimeName,
261
- this.connectionData,
262
- this.#buildCommand(localCommand)
263
- );
264
- }
265
233
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
266
234
  }
267
235
  /**
@@ -274,13 +242,6 @@ class RuntimeContext {
274
242
  getGlobalField(fieldName) {
275
243
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.GetGlobalField, [fieldName]);
276
244
  this.#currentCommand = null;
277
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
278
- return new import_InvocationContext.InvocationWsContext(
279
- this.runtimeName,
280
- this.connectionData,
281
- this.#buildCommand(localCommand)
282
- );
283
- }
284
245
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
285
246
  }
286
247
  /**
@@ -299,13 +260,6 @@ class RuntimeContext {
299
260
  ...args
300
261
  ]);
301
262
  this.#currentCommand = null;
302
- if (this.connectionData.connectionType === import_ConnectionType.ConnectionType.WEB_SOCKET) {
303
- return new import_InvocationContext.InvocationWsContext(
304
- this.runtimeName,
305
- this.connectionData,
306
- this.#buildCommand(localCommand)
307
- );
308
- }
309
263
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
310
264
  }
311
265
  /**
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var ComplexTypeResolver_exports = {};
30
20
  __export(ComplexTypeResolver_exports, {
@@ -39,7 +29,6 @@ var import_JavaTypeParsingFunctions = require("./typeParsingFunctions/JavaTypePa
39
29
  var import_NetcoreTypeParsingFunctions = require("./typeParsingFunctions/NetcoreTypeParsingFunctions.cjs");
40
30
  var import_NodejsTypeParsingFunctions = require("./typeParsingFunctions/NodejsTypeParsingFunctions.cjs");
41
31
  var import_PythonTypeParsingFunctions = require("./typeParsingFunctions/PythonTypeParsingFunctions.cjs");
42
- var util = __toESM(require("node:util"), 1);
43
32
  const import_meta = {};
44
33
  const dynamicImport = (0, import_Runtime.getRequire)(import_meta.url);
45
34
  class ComplexTypeResolver {
@@ -3,13 +3,6 @@ export class Interpreter {
3
3
  _handler: Handler | null;
4
4
  /** @type {Handler} */
5
5
  get handler(): Handler;
6
- /**
7
- *
8
- * @param {Command} command
9
- * @param {IConnectionData} connectionData
10
- * @returns
11
- */
12
- executeAsync(command: Command, connectionData: IConnectionData): Promise<import("../../utils/Command.js").Command>;
13
6
  /**
14
7
  *
15
8
  * @param {Command} command
@@ -188,12 +188,12 @@ export class InvocationContext {
188
188
  * Creates a null object of a specific type on the target runtime.
189
189
  * @param {string} methodName - The name of the method to invoke.
190
190
  * @param {...any} args - Method arguments.
191
- * @returns {InvocationContext|InvocationWsContext} An InvocationContext instance with the command to create a null object.
191
+ * @returns {InvocationContext} An InvocationContext instance with the command to create a null object.
192
192
  * TODO: connect documentation page url
193
193
  * @see [Javonet Guides](https://www.javonet.com/guides/)
194
194
  * @method
195
195
  */
196
- getInstanceMethodAsDelegate(methodName: string, ...args: any[]): InvocationContext | InvocationWsContext;
196
+ getInstanceMethodAsDelegate(methodName: string, ...args: any[]): InvocationContext;
197
197
  /**
198
198
  * Retrieves the type of the object from the target runtime.
199
199
  * @returns {Promise<string> | string} The type of the object.
@@ -230,28 +230,4 @@ export class InvocationContext {
230
230
  };
231
231
  #private;
232
232
  }
233
- export class InvocationWsContext extends InvocationContext {
234
- /**
235
- * Executes the current command.
236
- * Because invocation context is building the intent of executing particular expression on target environment, we call the initial state of invocation context as non-materialized.
237
- * The non-materialized context wraps either single command or chain of recursively nested commands.
238
- * Commands are becoming nested through each invocation of methods on Invocation Context.
239
- * Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
240
- * 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.
241
- * @returns {Promise<InvocationWsContext>} the InvocationContext after executing the command.
242
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
243
- * @async
244
- * @method
245
- */
246
- execute(): Promise<InvocationWsContext>;
247
- /**
248
- * Retrieves the type of the object from the target runtime.
249
- * @returns {Promise<string>} The type of the object.
250
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
251
- * @async
252
- * @method
253
- */
254
- getResultType(): Promise<string>;
255
- #private;
256
- }
257
233
  import { Command } from '../utils/Command.js';
@@ -1,4 +1,5 @@
1
1
  export type ConfigSource = import("../types.d.ts").ConfigSource;
2
+ /** @typedef {import('../types.d.ts').ConfigSource} ConfigSource */
2
3
  /**
3
4
  * The Javonet class is a singleton class that serves as the entry point for interacting with Javonet.
4
5
  * It provides methods to activate and initialize the Javonet SDK.
@@ -1,14 +1,18 @@
1
1
  // @ts-check
2
2
  import { getRequire } from '../../utils/Runtime.js'
3
3
  import { AbstractHandler } from './AbstractHandler.js'
4
- import { existsSync } from 'fs'
5
- import { resolve } from 'path'
6
4
 
7
5
  /**
8
6
  * @typedef {import('../../utils/Command.js').Command} Command
9
7
  */
10
8
 
11
- const dynamicImport = getRequire(import.meta.url)
9
+ /** @type {typeof import('fs').existsSync | null} */
10
+ let _existsSync = null
11
+
12
+ /** @type {typeof import('path').resolve | null} */
13
+ let _resolve = null
14
+
15
+ const requireDynamic = getRequire(import.meta.url)
12
16
  class LoadLibraryHandler extends AbstractHandler {
13
17
  requiredParametersCount = 1
14
18
  /** @type {string[]} */
@@ -33,12 +37,22 @@ class LoadLibraryHandler extends AbstractHandler {
33
37
  throw new Error('Cannot load module: Library path is required but was not provided')
34
38
  }
35
39
 
36
- const absolutePath = resolve(lib)
37
-
38
- if (!existsSync(lib) && !existsSync(absolutePath)) {
39
- throw new Error(`Cannot load module: Library not found: ${lib}`)
40
+ if (!_existsSync) {
41
+ const { existsSync } = requireDynamic('fs')
42
+ _existsSync = existsSync
43
+ }
44
+ if (!_resolve) {
45
+ const { resolve } = requireDynamic('path')
46
+ _resolve = resolve
40
47
  }
41
48
 
49
+ const absolutePath = _resolve?.(lib)
50
+
51
+ if (!_existsSync?.(lib ?? '') && !_existsSync?.(absolutePath ?? '')) {
52
+ throw new Error(`Cannot load module: Library not found: ${lib}`)
53
+ }
54
+
55
+
42
56
  let pathArray = lib.split(/[/\\]/)
43
57
  let libraryName = pathArray.length > 1 ? pathArray[pathArray.length - 1] : pathArray[0]
44
58
  libraryName = libraryName.replace('.js', '')
@@ -46,10 +60,10 @@ class LoadLibraryHandler extends AbstractHandler {
46
60
  let moduleExports
47
61
 
48
62
  try {
49
- moduleExports = dynamicImport(lib)
63
+ moduleExports = requireDynamic(lib)
50
64
  LoadLibraryHandler.loadedLibraries.push(lib)
51
65
  } catch (error) {
52
- throw Error('Cannot load module: ' + lib + "\n" + error)
66
+ throw Error('Cannot load module: ' + lib + '\n' + error)
53
67
  }
54
68
  // @ts-expect-error
55
69
  global[libraryName] = moduleExports
@@ -18,12 +18,9 @@ import { Handler } from '../handler/Handler.js'
18
18
  let _Receiver
19
19
  /** @type {typeof import('../transmitter/Transmitter.js').Transmitter} */
20
20
  let _Transmitter
21
- /** @type {typeof import('../transmitter/TransmitterWebsocket.js').TransmitterWebsocket | typeof import('../transmitter/TransmitterWebsocketBrowser.js').TransmitterWebsocketBrowser | null} */
22
- let _TransmitterWebsocket = null
21
+ /** @type {typeof import('../transmitter/TransmitterWebsocket.js').TransmitterWebsocket | typeof import('../transmitter/TransmitterWebsocketBrowser.js').TransmitterWebsocketBrowser} */
22
+ let _TransmitterWebsocket = isNodejsRuntime() ? TransmitterWebsocket : TransmitterWebsocketBrowser
23
23
 
24
- if (!_TransmitterWebsocket) {
25
- _TransmitterWebsocket = isNodejsRuntime() ? TransmitterWebsocket : TransmitterWebsocketBrowser
26
- }
27
24
 
28
25
  const requireDynamic = getRequire(import.meta.url)
29
26
 
@@ -43,119 +40,80 @@ export class Interpreter {
43
40
  *
44
41
  * @param {Command} command
45
42
  * @param {IConnectionData} connectionData
46
- * @returns
43
+ * @returns {Command | Promise<Command>}
47
44
  */
48
- async executeAsync(command, connectionData) {
45
+ execute(command, connectionData) {
49
46
  try {
50
47
  let messageByteArray = new CommandSerializer().serialize(command, connectionData)
51
- /** @type {Uint8Array | undefined} */
52
- let responseByteArray = undefined
53
-
54
- if (connectionData.connectionType === ConnectionType.WEB_SOCKET) {
55
- const _response = await _TransmitterWebsocket?.sendCommand(
56
- await messageByteArray,
57
- connectionData
58
- )
59
- if (_response) {
60
- const command = new CommandDeserializer(_response).deserialize()
61
- return command
62
- } else {
63
- throw new Error('Response not received from TransmitterWebsocket')
64
- }
65
- } else {
66
- if (!isNodejsRuntime()) {
67
- throw new Error('InMemory is only allowed in Nodejs runtime')
68
- }
69
-
70
- if (command.runtimeName === RuntimeName.Nodejs) {
71
- if (!_Receiver) {
72
- const { Receiver } = requireDynamic('../receiver/Receiver.js')
73
- _Receiver = Receiver
74
- }
75
- responseByteArray = await _Receiver?.sendCommand(await messageByteArray)
76
- } else {
77
- if (!_Transmitter) {
78
- const { Transmitter } = requireDynamic('../transmitter/Transmitter.js')
79
- _Transmitter = Transmitter
80
- }
81
- responseByteArray = await _Transmitter?.sendCommand(await messageByteArray)
82
- }
83
- }
84
48
 
85
- if (!responseByteArray) {
86
- throw new Error('No response received from Transmitter')
49
+ if (!(messageByteArray instanceof Uint8Array) && !(messageByteArray instanceof Promise)) {
50
+ throw new Error('Serialized message is neither Uint8Array nor Promise<Uint8Array>')
87
51
  }
88
52
 
89
- return new CommandDeserializer(responseByteArray).deserialize()
90
- } catch (error) {
91
- throw error
92
- }
93
- }
94
-
95
- /**
96
- *
97
- * @param {Command} command
98
- * @param {IConnectionData} connectionData
99
- * @returns {Command | Promise<Command>}
100
- */
101
- execute(command, connectionData) {
102
- try {
103
- let messageByteArray = new CommandSerializer().serialize(command, connectionData)
104
53
  /** @type {Promise<Uint8Array> | Uint8Array | undefined} */
105
54
  let responseByteArray = undefined
106
55
 
107
- if (connectionData.connectionType === ConnectionType.WEB_SOCKET) {
108
- throw new Error('Not supported')
56
+ if (!isNodejsRuntime() && connectionData.connectionType === ConnectionType.IN_MEMORY) {
57
+ throw new Error('Nodejs Core Error: inMemory is only allowed in Nodejs runtime, not in browser')
109
58
  }
110
- else {
111
- if (!isNodejsRuntime()) {
112
- throw new Error('InMemory is only allowed in Nodejs runtime')
113
- }
114
59
 
115
- if (command.runtimeName === RuntimeName.Nodejs && connectionData.connectionType === ConnectionType.IN_MEMORY) {
116
- if (!_Receiver) {
117
- const { Receiver } = requireDynamic('../receiver/Receiver.js')
118
- _Receiver = Receiver
119
- }
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
- }
130
- } else {
131
- if (!_Transmitter) {
132
- const { Transmitter } = requireDynamic('../transmitter/Transmitter.js')
133
- _Transmitter = Transmitter
134
- }
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
- }
60
+ if (
61
+ command.runtimeName === RuntimeName.Nodejs &&
62
+ connectionData.connectionType === ConnectionType.IN_MEMORY
63
+ ) {
64
+ if (!_Receiver) {
65
+ const { Receiver } = requireDynamic('../receiver/Receiver.js')
66
+ _Receiver = Receiver
145
67
  }
146
-
147
- if (!responseByteArray) {
148
- throw new Error('No response received from Transmitter')
68
+ if (!_Receiver) {
69
+ throw new Error('Nodejs Core Error: Receiver is undefined')
149
70
  }
150
-
151
- if (responseByteArray instanceof Promise) {
152
- return responseByteArray.then((resolvedResponse) => {
153
- return new CommandDeserializer(resolvedResponse).deserialize()
71
+ if (messageByteArray instanceof Promise) {
72
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
73
+ return _Receiver.sendCommand(resolvedMessage)
154
74
  })
75
+ } else if (messageByteArray instanceof Uint8Array) {
76
+ responseByteArray = _Receiver.sendCommand(messageByteArray)
77
+ }
78
+ } else if (
79
+ connectionData.connectionType === ConnectionType.IN_MEMORY ||
80
+ connectionData.connectionType === ConnectionType.TCP
81
+ ) {
82
+ if (!_Transmitter) {
83
+ const { Transmitter } = requireDynamic('../transmitter/Transmitter.js')
84
+ _Transmitter = Transmitter
85
+ }
86
+ if (!_Transmitter) {
87
+ throw new Error('Nodejs Core Error: Transmitter is undefined')
88
+ }
89
+ if (messageByteArray instanceof Uint8Array) {
90
+ responseByteArray = _Transmitter.sendCommand(messageByteArray)
155
91
  } else {
156
- return new CommandDeserializer(responseByteArray).deserialize()
92
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
93
+ return _Transmitter.sendCommand(resolvedMessage)
94
+ })
95
+ }
96
+ } else if (connectionData.connectionType === ConnectionType.WEB_SOCKET) {
97
+ if (messageByteArray instanceof Uint8Array) {
98
+ responseByteArray = _TransmitterWebsocket.sendCommand(messageByteArray, connectionData)
99
+ } else {
100
+ responseByteArray = messageByteArray.then((resolvedMessage) => {
101
+ return _TransmitterWebsocket.sendCommand(resolvedMessage, connectionData)
102
+ })
157
103
  }
158
104
  }
105
+
106
+ if (!responseByteArray) {
107
+ throw new Error('No response received from Transmitter')
108
+ }
109
+
110
+ if (responseByteArray instanceof Promise) {
111
+ return responseByteArray.then((resolvedResponse) => {
112
+ return new CommandDeserializer(resolvedResponse).deserialize()
113
+ })
114
+ } else {
115
+ return new CommandDeserializer(responseByteArray).deserialize()
116
+ }
159
117
  } catch (error) {
160
118
  throw error
161
119
  }
@@ -55,13 +55,6 @@ class InvocationContext {
55
55
  * @returns {InvocationContext}
56
56
  */
57
57
  #createInstanceContext(localCommand) {
58
- if (this.#connectionData.connectionType === ConnectionType.WEB_SOCKET) {
59
- return new InvocationWsContext(
60
- this.#runtimeName,
61
- this.#connectionData,
62
- this.#buildCommand(localCommand)
63
- )
64
- }
65
58
  return new InvocationContext(
66
59
  this.#runtimeName,
67
60
  this.#connectionData,
@@ -86,7 +79,6 @@ class InvocationContext {
86
79
  // this.execute();
87
80
  // }
88
81
  //}
89
-
90
82
  [Symbol.iterator] = () => {
91
83
  if (this.#currentCommand?.commandType !== CommandType.Reference) {
92
84
  throw new Error('Object is not iterable')
@@ -97,12 +89,12 @@ class InvocationContext {
97
89
  /** @type {InvocationContext | Promise<InvocationContext>} */
98
90
  const sizeCtx = /** @type {any} */ (this.getSize().execute())
99
91
  if (sizeCtx instanceof Promise) {
100
- sizeCtx.then((ctx) => {
101
- arraySize = Number(ctx.getValue())
102
- })
92
+ sizeCtx.then((ctx) => {
93
+ arraySize = Number(ctx.getValue())
94
+ })
103
95
  } else {
104
- arraySize = Number(sizeCtx.getValue())
105
- }
96
+ arraySize = Number(sizeCtx.getValue())
97
+ }
106
98
 
107
99
  return {
108
100
  next: () => ({
@@ -134,7 +126,7 @@ class InvocationContext {
134
126
 
135
127
  this.#responseCommand = this.#interpreter.execute(this.#currentCommand, this.#connectionData)
136
128
 
137
- const handleResponse = (/** @type {Command } */ resolvedResponse) => {
129
+ const handleResponse = (/** @type {Command} */ resolvedResponse) => {
138
130
  if (!resolvedResponse) {
139
131
  throw new Error('responseCommand is undefined in Invocation Context execute method')
140
132
  }
@@ -395,7 +387,7 @@ class InvocationContext {
395
387
  * Creates a null object of a specific type on the target runtime.
396
388
  * @param {string} methodName - The name of the method to invoke.
397
389
  * @param {...any} args - Method arguments.
398
- * @returns {InvocationContext|InvocationWsContext} An InvocationContext instance with the command to create a null object.
390
+ * @returns {InvocationContext} An InvocationContext instance with the command to create a null object.
399
391
  * TODO: connect documentation page url
400
392
  * @see [Javonet Guides](https://www.javonet.com/guides/)
401
393
  * @method
@@ -421,10 +413,18 @@ class InvocationContext {
421
413
  this.#connectionData,
422
414
  this.#buildCommand(localCommand)
423
415
  )
424
- /** @type {InvocationContext} */
425
- const execCtx = /** @type {any} */ (invocationContext.execute())
426
- const result = execCtx.getValue()
427
- return /** @type {string} */ (result)
416
+ /** @type {InvocationContext | Promise<InvocationContext>} */
417
+ const execCtx = invocationContext.execute()
418
+
419
+ /**
420
+ * @param {InvocationContext} invCtx
421
+ * @returns {string}
422
+ */
423
+ const extract = (invCtx) => String(invCtx.getValue())
424
+
425
+ console.log(execCtx)
426
+
427
+ return execCtx instanceof Promise ? execCtx.then(extract) : extract(execCtx)
428
428
  }
429
429
 
430
430
  /**
@@ -457,7 +457,9 @@ class InvocationContext {
457
457
  }
458
458
 
459
459
  // Normalize to Promise
460
- return localInvCtx.#responseCommand instanceof Promise ? localInvCtx.#responseCommand.then(extract) : localInvCtx.#responseCommand?.payload
460
+ return localInvCtx.#responseCommand instanceof Promise
461
+ ? localInvCtx.#responseCommand.then(extract)
462
+ : localInvCtx.#responseCommand?.payload
461
463
  }
462
464
 
463
465
  /**
@@ -521,143 +523,4 @@ class InvocationContext {
521
523
  }
522
524
  }
523
525
 
524
- class InvocationWsContext extends InvocationContext {
525
- /** @type {RuntimeNameType} */
526
- #runtimeName
527
- /** @type {IConnectionData} */
528
- #connectionData
529
- /** @type {Command | null} */
530
- #currentCommand
531
- /** @type {Command | null} */
532
- #responseCommand
533
- /** @type {Interpreter | null} */
534
- #interpreter
535
- /** @type {boolean} */
536
- #isExecuted
537
-
538
- /**
539
- * @param {RuntimeNameType} runtimeName
540
- * @param {IConnectionData} connectionData
541
- * @param {Command} command
542
- * @param {boolean} isExecuted
543
- */
544
- constructor(runtimeName, connectionData, command, isExecuted = false) {
545
- super(runtimeName, connectionData, command, isExecuted)
546
-
547
- this.#runtimeName = runtimeName
548
- this.#connectionData = connectionData
549
- this.#currentCommand = command
550
- this.#responseCommand = null
551
- this.#isExecuted = isExecuted
552
- this.#interpreter = null
553
- }
554
-
555
- /**
556
- * Executes the current command.
557
- * Because invocation context is building the intent of executing particular expression on target environment, we call the initial state of invocation context as non-materialized.
558
- * The non-materialized context wraps either single command or chain of recursively nested commands.
559
- * Commands are becoming nested through each invocation of methods on Invocation Context.
560
- * Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
561
- * 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.
562
- * @returns {Promise<InvocationWsContext>} the InvocationContext after executing the command.
563
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
564
- * @async
565
- * @method
566
- */
567
- async execute() {
568
- if (this.#currentCommand === null) {
569
- throw new Error('currentCommand is undefined in Invocation Context execute method')
570
- }
571
-
572
- if (!this.#interpreter) {
573
- this.#interpreter = new Interpreter()
574
- }
575
- this.#responseCommand = await this.#interpreter.executeAsync(
576
- this.#currentCommand,
577
- this.#connectionData
578
- )
579
-
580
- if (this.#responseCommand === undefined) {
581
- throw new Error('responseCommand is undefined in Invocation Context execute method')
582
- }
583
- if (this.#responseCommand.commandType === CommandType.Exception) {
584
- throw ExceptionThrower.throwException(this.#responseCommand)
585
- }
586
- if (this.#responseCommand.commandType === CommandType.CreateClassInstance) {
587
- this.#currentCommand = this.#responseCommand
588
- this.#isExecuted = true
589
- return this
590
- }
591
-
592
- return new InvocationWsContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true)
593
- }
594
-
595
- /**
596
- * Retrieves the type of the object from the target runtime.
597
- * @returns {Promise<string>} The type of the object.
598
- * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
599
- * @async
600
- * @method
601
- */
602
- async getResultType() {
603
- const localCommand = new Command(this.#runtimeName, CommandType.GetResultType, [])
604
- const invocationContext = new InvocationWsContext(
605
- this.#runtimeName,
606
- this.#connectionData,
607
- this.#buildCommand(localCommand)
608
- )
609
- const result = await invocationContext.execute()
610
- return /** @type {string} */ (result.getValue())
611
- }
612
-
613
- /**
614
- * @param {Command} command
615
- * @returns {Command}
616
- */
617
- #buildCommand(command) {
618
- for (let i = 0; i < command.payload.length; i++) {
619
- command.payload[i] = this.#encapsulatePayloadItem(command.payload[i])
620
- }
621
- return command.prependArgToPayload(this.#currentCommand)
622
- }
623
-
624
- /**
625
- * @param {unknown} payloadItem
626
- * @returns {Command|null}
627
- */
628
- #encapsulatePayloadItem(payloadItem) {
629
- // eslint-disable-next-line valid-typeof
630
- if (payloadItem instanceof Command) {
631
- for (let i = 0; i < payloadItem.payload.length; i++) {
632
- payloadItem.payload[i] = this.#encapsulatePayloadItem(payloadItem.payload[i])
633
- }
634
- return payloadItem
635
- // eslint-disable-next-line valid-typeof
636
- } else if (payloadItem instanceof InvocationContext || payloadItem instanceof InvocationWsContext) {
637
- return payloadItem.get_current_command()
638
- } else if (payloadItem instanceof Array) {
639
- const copiedArray = payloadItem.map((item) => this.#encapsulatePayloadItem(item))
640
- return new Command(this.#runtimeName, CommandType.Array, copiedArray)
641
- } else if (typeof payloadItem === 'function') {
642
- let newArray = new Array(payloadItem.length + 1)
643
- for (let i = 0; i < newArray.length; i++) {
644
- newArray[i] = typeof Object
645
- }
646
- const args = [delegatesCacheInstance.addDelegate(payloadItem), RuntimeName.Nodejs].push(
647
- ...newArray
648
- )
649
- return new Command(this.#runtimeName, CommandType.PassDelegate, args)
650
- } else if (TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
651
- return new Command(this.#runtimeName, CommandType.Value, [payloadItem])
652
- } else {
653
- throw Error(
654
- 'Unsupported payload item type: ' +
655
- (payloadItem?.constructor?.name || typeof payloadItem) +
656
- ' for payload item: ' +
657
- payloadItem
658
- )
659
- }
660
- }
661
- }
662
-
663
- export { InvocationContext, InvocationWsContext }
526
+ export { InvocationContext }
@@ -15,20 +15,6 @@ import { ConfigPriority } from './configuration/ConfigPriority.js'
15
15
 
16
16
  /** @typedef {import('../types.d.ts').ConfigSource} ConfigSource */
17
17
 
18
- const requireDynamic = getRequire(import.meta.url)
19
-
20
- /** @type {typeof import('../core/transmitter/Transmitter.js').Transmitter | null} */
21
- let _Transmitter = null
22
-
23
- if (isNodejsRuntime()) {
24
- try {
25
- const { Transmitter } = requireDynamic('../core/transmitter/Transmitter.js')
26
- _Transmitter = Transmitter
27
- } catch (error) {
28
- throw error
29
- }
30
- }
31
-
32
18
  //static constructor not supported in nodeJS 12.20
33
19
  //SDKExceptionHelper.sendExceptionToAppInsights("SdkMessage", "Javonet SDK initialized");
34
20
 
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
  import { Command } from '../utils/Command.js'
3
3
  import { CommandType } from '../utils/CommandType.js'
4
- import { InvocationContext, InvocationWsContext } from './InvocationContext.js'
4
+ import { InvocationContext } from './InvocationContext.js'
5
5
  import { ConnectionType } from '../utils/ConnectionType.js'
6
6
  import { ExceptionThrower } from '../utils/exception/ExceptionThrower.js'
7
7
  import { RuntimeName } from '../utils/RuntimeName.js'
@@ -9,7 +9,7 @@ import { Interpreter } from '../core/interpreter/Interpreter.js'
9
9
  import { delegatesCacheInstance } from '../core/delegatesCache/DelegatesCache.js'
10
10
  import { TypesHandler } from '../utils/TypesHandler.js'
11
11
  import { UtilsConst } from '../utils/UtilsConst.js'
12
- import { getRequire } from '../utils/Runtime.js'
12
+ import { getRequire, isNodejsRuntime } from '../utils/Runtime.js'
13
13
 
14
14
  /**
15
15
  * @typedef {import('../types.d.ts').RuntimeName} RuntimeNameType
@@ -81,6 +81,10 @@ class RuntimeContext {
81
81
  * @returns {RuntimeContext}
82
82
  */
83
83
  static getInstance(runtimeName, connectionData) {
84
+ if (!isNodejsRuntime() && connectionData.connectionType === ConnectionType.IN_MEMORY) {
85
+ throw new Error('Nodejs Core Error: inMemory is only allowed in Nodejs runtime, not in browser')
86
+ }
87
+
84
88
  switch (connectionData.connectionType) {
85
89
  case ConnectionType.IN_MEMORY:
86
90
  const key = String(runtimeName)
@@ -181,13 +185,6 @@ class RuntimeContext {
181
185
  getType(typeName, ...args) {
182
186
  let localCommand = new Command(this.runtimeName, CommandType.GetType, [typeName, ...args])
183
187
  this.#currentCommand = null
184
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
185
- return new InvocationWsContext(
186
- this.runtimeName,
187
- this.connectionData,
188
- this.#buildCommand(localCommand)
189
- )
190
- }
191
188
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
192
189
  }
193
190
 
@@ -203,13 +200,6 @@ class RuntimeContext {
203
200
  cast(...args) {
204
201
  let localCommand = new Command(this.runtimeName, CommandType.Cast, args)
205
202
  this.#currentCommand = null
206
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
207
- return new InvocationWsContext(
208
- this.runtimeName,
209
- this.connectionData,
210
- this.#buildCommand(localCommand)
211
- )
212
- }
213
203
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
214
204
  }
215
205
 
@@ -225,13 +215,6 @@ class RuntimeContext {
225
215
  getEnumItem(...args) {
226
216
  let localCommand = new Command(this.runtimeName, CommandType.GetEnumItem, args)
227
217
  this.#currentCommand = null
228
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
229
- return new InvocationWsContext(
230
- this.runtimeName,
231
- this.connectionData,
232
- this.#buildCommand(localCommand)
233
- )
234
- }
235
218
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
236
219
  }
237
220
 
@@ -247,13 +230,6 @@ class RuntimeContext {
247
230
  asRef(...args) {
248
231
  let localCommand = new Command(this.runtimeName, CommandType.AsRef, args)
249
232
  this.#currentCommand = null
250
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
251
- return new InvocationWsContext(
252
- this.runtimeName,
253
- this.connectionData,
254
- this.#buildCommand(localCommand)
255
- )
256
- }
257
233
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
258
234
  }
259
235
 
@@ -269,13 +245,6 @@ class RuntimeContext {
269
245
  asOut(...args) {
270
246
  let localCommand = new Command(this.runtimeName, CommandType.AsOut, args)
271
247
  this.#currentCommand = null
272
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
273
- return new InvocationWsContext(
274
- this.runtimeName,
275
- this.connectionData,
276
- this.#buildCommand(localCommand)
277
- )
278
- }
279
248
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
280
249
  }
281
250
 
@@ -289,13 +258,6 @@ class RuntimeContext {
289
258
  getGlobalField(fieldName) {
290
259
  let localCommand = new Command(this.runtimeName, CommandType.GetGlobalField, [fieldName])
291
260
  this.#currentCommand = null
292
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
293
- return new InvocationWsContext(
294
- this.runtimeName,
295
- this.connectionData,
296
- this.#buildCommand(localCommand)
297
- )
298
- }
299
261
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
300
262
  }
301
263
 
@@ -315,13 +277,6 @@ class RuntimeContext {
315
277
  ...args,
316
278
  ])
317
279
  this.#currentCommand = null
318
- if (this.connectionData.connectionType === ConnectionType.WEB_SOCKET) {
319
- return new InvocationWsContext(
320
- this.runtimeName,
321
- this.connectionData,
322
- this.#buildCommand(localCommand)
323
- )
324
- }
325
280
  return new InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand))
326
281
  }
327
282
 
@@ -7,7 +7,6 @@ import { JavaTypeParsingFunctions } from './typeParsingFunctions/JavaTypeParsing
7
7
  import { NetcoreTypeParsingFunctions } from './typeParsingFunctions/NetcoreTypeParsingFunctions.js'
8
8
  import { NodejsTypeParsingFunctions } from './typeParsingFunctions/NodejsTypeParsingFunctions.js'
9
9
  import { PythonTypeParsingFunctions } from './typeParsingFunctions/PythonTypeParsingFunctions.js'
10
- import * as util from 'node:util'
11
10
 
12
11
  const dynamicImport = getRequire(import.meta.url)
13
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javonet-nodejs-sdk",
3
- "version": "2.6.6",
3
+ "version": "2.6.7",
4
4
  "description": "Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology. It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products. Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today! For more information check out our guides at https://www.javonet.com/guides/v2/",
5
5
  "keywords": [],
6
6
  "author": "SdNCenter Sp. z o. o.",
@@ -30,17 +30,6 @@
30
30
  "default": "./lib/utils/CreateRequire.node.js"
31
31
  }
32
32
  },
33
- "jest": {
34
- "verbose": true,
35
- "testResultsProcessor": "./node_modules/jest-junit-reporter",
36
- "coverageReporters": [
37
- "json",
38
- "lcov",
39
- "text",
40
- "clover",
41
- "cobertura"
42
- ]
43
- },
44
33
  "scripts": {
45
34
  "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/unitTests tests/functional -t=\"(Unit|Functional)\" --maxWorkers=3 --colors --coverage",
46
35
  "webserviceTests": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/webSocketClientTests --maxWorkers=3 --colors",