javonet-nodejs-sdk 2.6.7 → 2.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/core/handler/Handler.cjs +2 -7
  2. package/dist/core/handler/LoadLibraryHandler.cjs +15 -9
  3. package/dist/core/handler/PassDelegateHandler.cjs +2 -2
  4. package/dist/core/interpreter/Interpreter.cjs +11 -33
  5. package/dist/core/protocol/CommandSerializer.cjs +3 -8
  6. package/dist/core/receiver/Receiver.cjs +6 -6
  7. package/dist/sdk/Activator.cjs +44 -0
  8. package/dist/sdk/ActivatorDetails.cjs +13 -3
  9. package/dist/sdk/ConfigRuntimeFactory.cjs +9 -0
  10. package/dist/sdk/InvocationContext.cjs +49 -56
  11. package/dist/sdk/Javonet.cjs +3 -0
  12. package/dist/sdk/RuntimeContext.cjs +8 -8
  13. package/dist/sdk/configuration/ConfigSourceResolver.cjs +43 -21
  14. package/dist/sdk/tools/ComplexTypeResolver.cjs +84 -34
  15. package/dist/types/core/handler/Handler.d.ts +2 -1
  16. package/dist/types/core/handler/PassDelegateHandler.d.ts +2 -2
  17. package/dist/types/core/interpreter/Interpreter.d.ts +2 -2
  18. package/dist/types/core/protocol/CommandSerializer.d.ts +3 -3
  19. package/dist/types/core/receiver/Receiver.d.ts +4 -4
  20. package/dist/types/sdk/Activator.d.ts +12 -0
  21. package/dist/types/sdk/ActivatorDetails.d.ts +5 -3
  22. package/dist/types/sdk/ConfigRuntimeFactory.d.ts +7 -0
  23. package/dist/types/sdk/InvocationContext.d.ts +11 -10
  24. package/dist/types/sdk/Javonet.d.ts +2 -1
  25. package/dist/types/sdk/RuntimeContext.d.ts +4 -3
  26. package/dist/types/sdk/configuration/ConfigSourceResolver.d.ts +21 -4
  27. package/dist/types/sdk/tools/ComplexTypeResolver.d.ts +21 -5
  28. package/dist/types/utils/Primitives.d.ts +5 -0
  29. package/dist/utils/Primitives.cjs +201 -0
  30. package/lib/core/handler/Handler.js +2 -7
  31. package/lib/core/handler/LoadLibraryHandler.js +28 -14
  32. package/lib/core/handler/PassDelegateHandler.js +2 -2
  33. package/lib/core/interpreter/Interpreter.js +11 -35
  34. package/lib/core/protocol/CommandSerializer.js +5 -10
  35. package/lib/core/receiver/Receiver.js +6 -6
  36. package/lib/sdk/Activator.js +22 -0
  37. package/lib/sdk/ActivatorDetails.js +18 -3
  38. package/lib/sdk/ConfigRuntimeFactory.js +10 -0
  39. package/lib/sdk/InvocationContext.js +51 -65
  40. package/lib/sdk/Javonet.js +2 -0
  41. package/lib/sdk/RuntimeContext.js +8 -8
  42. package/lib/sdk/configuration/ConfigSourceResolver.js +47 -14
  43. package/lib/sdk/tools/ComplexTypeResolver.js +104 -42
  44. package/lib/utils/Primitives.js +193 -0
  45. package/package.json +1 -1
@@ -142,18 +142,13 @@ class Handler {
142
142
  }
143
143
  /**
144
144
  * @param {Command} command
145
+ * @returns {Promise<Command> | Command}
145
146
  */
146
147
  handleCommand(command) {
147
148
  try {
148
149
  if (command.commandType === import_CommandType.CommandType.RetrieveArray) {
149
150
  const responseArray = handlers[import_CommandType.CommandType.Reference].handleCommand(command.payload[0]);
150
- if (responseArray instanceof Promise) {
151
- return responseArray.then((resolvedResponseArray) => {
152
- return import_Command.Command.createArrayResponse(resolvedResponseArray, command.runtimeName);
153
- });
154
- } else {
155
- return import_Command.Command.createArrayResponse(responseArray, command.runtimeName);
156
- }
151
+ return import_Command.Command.createArrayResponse(responseArray, command.runtimeName);
157
152
  }
158
153
  const response = handlers[command.commandType].handleCommand(command);
159
154
  return this.parseCommand(response, command.runtimeName);
@@ -41,8 +41,8 @@ class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
41
41
  if (command.payload.length < this.requiredParametersCount) {
42
42
  throw new Error("Load Library parameters mismatch");
43
43
  }
44
- let { payload } = command;
45
- let [lib] = payload;
44
+ const { payload } = command;
45
+ const [lib] = payload;
46
46
  if (!lib) {
47
47
  throw new Error("Cannot load module: Library path is required but was not provided");
48
48
  }
@@ -54,19 +54,25 @@ class LoadLibraryHandler extends import_AbstractHandler.AbstractHandler {
54
54
  const { resolve } = requireDynamic("path");
55
55
  _resolve = resolve;
56
56
  }
57
- const absolutePath = _resolve?.(lib);
58
- if (!_existsSync?.(lib ?? "") && !_existsSync?.(absolutePath ?? "")) {
57
+ const absolutePath = _resolve ? _resolve(lib) : lib;
58
+ const candidatePaths = [lib, absolutePath];
59
+ const existingPath = candidatePaths.find((p) => _existsSync && _existsSync(p));
60
+ if (!existingPath) {
59
61
  throw new Error(`Cannot load module: Library not found: ${lib}`);
60
62
  }
61
- let pathArray = lib.split(/[/\\]/);
63
+ const normalizedPath = _resolve ? _resolve(existingPath) : existingPath;
64
+ if (LoadLibraryHandler.loadedLibraries.includes(normalizedPath)) {
65
+ return 0;
66
+ }
67
+ const pathArray = normalizedPath.split(/[/\\]/);
62
68
  let libraryName = pathArray.length > 1 ? pathArray[pathArray.length - 1] : pathArray[0];
63
- libraryName = libraryName.replace(".js", "");
69
+ libraryName = libraryName.replace(/\.js$/i, "");
64
70
  let moduleExports;
65
71
  try {
66
- moduleExports = requireDynamic(lib);
67
- LoadLibraryHandler.loadedLibraries.push(lib);
72
+ moduleExports = requireDynamic(normalizedPath);
73
+ LoadLibraryHandler.loadedLibraries.push(normalizedPath);
68
74
  } catch (error) {
69
- throw Error("Cannot load module: " + lib + "\n" + error);
75
+ throw new Error("Cannot load module: " + normalizedPath + "\n" + error);
70
76
  }
71
77
  global[libraryName] = moduleExports;
72
78
  for (const [key, value] of Object.entries(moduleExports)) {
@@ -110,9 +110,9 @@ class PassDelegateHandler extends import_AbstractHandler.AbstractHandler {
110
110
  /**
111
111
  * Creates a method call to execute the command.
112
112
  * @param {Command} command - The command object.
113
- * @returns {any} The response object.
113
+ * @returns {Promise<any>} The response object.
114
114
  */
115
- createExecuteCall(command) {
115
+ async createExecuteCall(command) {
116
116
  return this.interpreter?.execute(command, new import_InMemoryConnectionData.InMemoryConnectionData());
117
117
  }
118
118
  /**
@@ -48,17 +48,19 @@ class Interpreter {
48
48
  *
49
49
  * @param {Command} command
50
50
  * @param {IConnectionData} connectionData
51
- * @returns {Command | Promise<Command>}
51
+ * @returns {Promise<Command>}
52
52
  */
53
- execute(command, connectionData) {
53
+ async execute(command, connectionData) {
54
54
  try {
55
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>");
56
+ if (!(messageByteArray instanceof Uint8Array)) {
57
+ throw new Error("Serialized message is not Uint8Array");
58
58
  }
59
59
  let responseByteArray = void 0;
60
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");
61
+ throw new Error(
62
+ "Nodejs Core Error: inMemory is only allowed in Nodejs runtime, not in browser"
63
+ );
62
64
  }
63
65
  if (command.runtimeName === import_RuntimeName.RuntimeName.Nodejs && connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY) {
64
66
  if (!_Receiver) {
@@ -68,13 +70,7 @@ class Interpreter {
68
70
  if (!_Receiver) {
69
71
  throw new Error("Nodejs Core Error: Receiver is undefined");
70
72
  }
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);
77
- }
73
+ responseByteArray = await _Receiver.sendCommand(messageByteArray);
78
74
  } else if (connectionData.connectionType === import_ConnectionType.ConnectionType.IN_MEMORY || connectionData.connectionType === import_ConnectionType.ConnectionType.TCP) {
79
75
  if (!_Transmitter) {
80
76
  const { Transmitter } = require("../transmitter/Transmitter.cjs");
@@ -83,32 +79,14 @@ class Interpreter {
83
79
  if (!_Transmitter) {
84
80
  throw new Error("Nodejs Core Error: Transmitter is undefined");
85
81
  }
86
- if (messageByteArray instanceof Uint8Array) {
87
- responseByteArray = _Transmitter.sendCommand(messageByteArray);
88
- } else {
89
- responseByteArray = messageByteArray.then((resolvedMessage) => {
90
- return _Transmitter.sendCommand(resolvedMessage);
91
- });
92
- }
82
+ responseByteArray = await _Transmitter.sendCommand(messageByteArray);
93
83
  } 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
- });
100
- }
84
+ responseByteArray = await _TransmitterWebsocket.sendCommand(messageByteArray, connectionData);
101
85
  }
102
86
  if (!responseByteArray) {
103
87
  throw new Error("No response received from Transmitter");
104
88
  }
105
- if (responseByteArray instanceof Promise) {
106
- return responseByteArray.then((resolvedResponse) => {
107
- return new import_CommandDeserializer.CommandDeserializer(resolvedResponse).deserialize();
108
- });
109
- } else {
110
- return new import_CommandDeserializer.CommandDeserializer(responseByteArray).deserialize();
111
- }
89
+ return new import_CommandDeserializer.CommandDeserializer(responseByteArray).deserialize();
112
90
  } catch (error) {
113
91
  throw error;
114
92
  }
@@ -30,21 +30,16 @@ var import_TypesHandler = require("../../utils/TypesHandler.cjs");
30
30
  class CommandSerializer {
31
31
  /**
32
32
  * Serializes the root command with connection data and optional runtime version.
33
- * @param {Promise<Command> | Command} rootCommand
33
+ * @param {Command} rootCommand
34
34
  * @param {IConnectionData} connectionData
35
35
  * @param {number} runtimeVersion
36
- * @returns {Promise<Uint8Array> | Uint8Array}
36
+ * @returns {Uint8Array}
37
37
  */
38
38
  serialize(rootCommand, connectionData, runtimeVersion = 0) {
39
39
  const buffers = [];
40
- if (rootCommand instanceof Promise) {
41
- return rootCommand.then((resolvedCommand) => {
42
- return this.serialize(resolvedCommand, connectionData, runtimeVersion);
43
- });
44
- }
45
40
  buffers.push(Uint8Array.of(rootCommand.runtimeName, runtimeVersion));
46
41
  if (connectionData) {
47
- buffers.push(connectionData.serializeConnectionData());
42
+ buffers.push(Uint8Array.from(connectionData.serializeConnectionData()));
48
43
  } else {
49
44
  buffers.push(Uint8Array.of(0, 0, 0, 0, 0, 0, 0));
50
45
  }
@@ -39,11 +39,11 @@ class Receiver {
39
39
  }
40
40
  /**
41
41
  * @param {Uint8Array} messageByteArray
42
- * @returns {Promise<Uint8Array> | Uint8Array}
42
+ * @returns {Promise<Uint8Array>}
43
43
  */
44
- static sendCommand(messageByteArray) {
44
+ static async sendCommand(messageByteArray) {
45
45
  try {
46
- let command = new import_Interpreter.Interpreter().process(messageByteArray);
46
+ let command = await new import_Interpreter.Interpreter().process(messageByteArray);
47
47
  return new import_CommandSerializer.CommandSerializer().serialize(command, this.connectionData);
48
48
  } catch (error) {
49
49
  const exceptionCommand = import_ExceptionSerializer.ExceptionSerializer.serializeException(
@@ -55,13 +55,13 @@ class Receiver {
55
55
  }
56
56
  /**
57
57
  * @param {Uint8Array} messageByteArray
58
- * @returns {Promise<Uint8Array> | Uint8Array}
58
+ * @returns {Promise<Uint8Array>}
59
59
  */
60
- static heartBeat(messageByteArray) {
60
+ static async heartBeat(messageByteArray) {
61
61
  let response = new Uint8Array(2);
62
62
  response[0] = messageByteArray[11];
63
63
  response[1] = messageByteArray[12] - 2;
64
- return response;
64
+ return Promise.resolve(response);
65
65
  }
66
66
  }
67
67
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Activator_exports = {};
20
+ __export(Activator_exports, {
21
+ Activator: () => Activator
22
+ });
23
+ module.exports = __toCommonJS(Activator_exports);
24
+ class Activator {
25
+ /**
26
+ * Create a new instance of a type
27
+ * @param {Function} Type - The constructor function/class
28
+ * @param {any[] | any} args - The arguments to pass to the constructor
29
+ * @returns {any} The new instance
30
+ */
31
+ static createInstance(Type, args) {
32
+ if (args == null) {
33
+ args = [];
34
+ }
35
+ if (!Array.isArray(args)) {
36
+ args = [args];
37
+ }
38
+ return new Type(...args);
39
+ }
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ Activator
44
+ });
@@ -22,13 +22,23 @@ __export(ActivatorDetails_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(ActivatorDetails_exports);
24
24
  class ActivatorDetails {
25
+ /** @type {Function} */
26
+ Type;
27
+ /** @type {any[]} */
28
+ arguments;
25
29
  /**
26
30
  * @param {Function} type - The constructor function/class
27
- * @param {any[]} [args] - Arguments to pass to constructor
31
+ * @param {any[]|any} [args] - Arguments to pass to constructor (array or single value)
28
32
  */
29
33
  constructor(type, args = []) {
30
- this.type = type;
31
- this.arguments = args;
34
+ this.Type = type;
35
+ if (args == null) {
36
+ this.arguments = [];
37
+ } else if (Array.isArray(args)) {
38
+ this.arguments = args;
39
+ } else {
40
+ this.arguments = [args];
41
+ }
32
42
  }
33
43
  }
34
44
  // Annotate the CommonJS export names for ESM import in node:
@@ -105,6 +105,15 @@ class ConfigRuntimeFactory {
105
105
  nodejs(configName = "default") {
106
106
  return this.#getRuntimeContext(import_RuntimeName.RuntimeName.Nodejs, configName);
107
107
  }
108
+ /**
109
+ * Creates RuntimeContext instance to interact with the Php runtime.
110
+ * @param {string} [configName="default"] - The name of the configuration to use (optional).
111
+ * @return {RuntimeContext} a RuntimeContext instance for the Php runtime
112
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
113
+ */
114
+ php(configName = "default") {
115
+ return this.#getRuntimeContext(import_RuntimeName.RuntimeName.Php, configName);
116
+ }
108
117
  /**
109
118
  * Creates RuntimeContext instance to interact with the Python 2.7 runtime.
110
119
  * @param {string} [configName="default"] - The name of the configuration to use (optional).
@@ -36,7 +36,7 @@ class InvocationContext {
36
36
  #connectionData;
37
37
  /** @type {Command | null} */
38
38
  #currentCommand = null;
39
- /** @type {Command | Promise<Command> | null} */
39
+ /** @type {Command | null} */
40
40
  #responseCommand = null;
41
41
  /** @type {boolean} */
42
42
  #isExecuted = false;
@@ -84,30 +84,21 @@ class InvocationContext {
84
84
  // this.execute();
85
85
  // }
86
86
  //}
87
- [Symbol.iterator] = () => {
87
+ /**
88
+ * Async iterator for InvocationContext arrays
89
+ * Use: for await (const item of invocationContext) { ... }
90
+ * @returns {AsyncGenerator<InvocationContext, void, unknown>}
91
+ */
92
+ async *[Symbol.asyncIterator]() {
88
93
  if (this.#currentCommand?.commandType !== import_CommandType.CommandType.Reference) {
89
94
  throw new Error("Object is not iterable");
90
95
  }
91
- let position = -1;
92
- let arraySize = 0;
93
- const sizeCtx = (
94
- /** @type {any} */
95
- this.getSize().execute()
96
- );
97
- if (sizeCtx instanceof Promise) {
98
- sizeCtx.then((ctx) => {
99
- arraySize = Number(ctx.getValue());
100
- });
101
- } else {
102
- arraySize = Number(sizeCtx.getValue());
96
+ const sizeCtx = await this.getSize().execute();
97
+ const arraySize = Number(sizeCtx.getValue());
98
+ for (let position = 0; position < arraySize; position++) {
99
+ yield this.getIndex(position);
103
100
  }
104
- return {
105
- next: () => ({
106
- value: this.getIndex(++position),
107
- done: position >= arraySize
108
- })
109
- };
110
- };
101
+ }
111
102
  /**
112
103
  * Executes the current command.
113
104
  * 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.
@@ -115,37 +106,30 @@ class InvocationContext {
115
106
  * Commands are becoming nested through each invocation of methods on Invocation Context.
116
107
  * Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
117
108
  * Developer can decide on any moment of the materialization for the context taking full control of the chunks of the expression being transferred and processed on target runtime.
118
- * @returns {Promise<InvocationContext> | InvocationContext} the InvocationContext after executing the command.
109
+ * @returns {Promise<InvocationContext>} the InvocationContext after executing the command.
119
110
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
120
111
  * @method
121
112
  */
122
- execute() {
113
+ async execute() {
123
114
  if (this.#currentCommand === null) {
124
115
  throw new Error("currentCommand is undefined in Invocation Context execute method");
125
116
  }
126
117
  if (!this.#interpreter) {
127
118
  this.#interpreter = new import_Interpreter.Interpreter();
128
119
  }
129
- this.#responseCommand = this.#interpreter.execute(this.#currentCommand, this.#connectionData);
130
- const handleResponse = (resolvedResponse) => {
131
- if (!resolvedResponse) {
132
- throw new Error("responseCommand is undefined in Invocation Context execute method");
133
- }
134
- if (resolvedResponse.commandType === import_CommandType.CommandType.Exception) {
135
- throw import_ExceptionThrower.ExceptionThrower.throwException(resolvedResponse);
136
- }
137
- if (resolvedResponse.commandType === import_CommandType.CommandType.CreateClassInstance) {
138
- this.#currentCommand = resolvedResponse;
139
- this.#isExecuted = true;
140
- return this;
141
- }
142
- return new InvocationContext(this.#runtimeName, this.#connectionData, resolvedResponse, true);
143
- };
144
- if (this.#responseCommand instanceof Promise) {
145
- return this.#responseCommand.then(handleResponse);
146
- } else {
147
- return handleResponse(this.#responseCommand);
120
+ this.#responseCommand = await this.#interpreter.execute(this.#currentCommand, this.#connectionData);
121
+ if (!this.#responseCommand) {
122
+ throw new Error("responseCommand is undefined in Invocation Context execute method");
123
+ }
124
+ if (this.#responseCommand.commandType === import_CommandType.CommandType.Exception) {
125
+ throw import_ExceptionThrower.ExceptionThrower.throwException(this.#responseCommand);
148
126
  }
127
+ if (this.#responseCommand.commandType === import_CommandType.CommandType.CreateClassInstance) {
128
+ this.#currentCommand = this.#responseCommand;
129
+ this.#isExecuted = true;
130
+ return this;
131
+ }
132
+ return new InvocationContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true);
149
133
  }
150
134
  /**
151
135
  * Invokes a static method on the target runtime.
@@ -382,21 +366,19 @@ class InvocationContext {
382
366
  }
383
367
  /**
384
368
  * Retrieves the type of the object from the target runtime.
385
- * @returns {Promise<string> | string} The type of the object.
369
+ * @returns {Promise<string>} The type of the object.
386
370
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
387
371
  * @method
388
372
  */
389
- getResultType() {
373
+ async getResultType() {
390
374
  const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
391
375
  const invocationContext = new InvocationContext(
392
376
  this.#runtimeName,
393
377
  this.#connectionData,
394
378
  this.#buildCommand(localCommand)
395
379
  );
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);
380
+ const execCtx = await invocationContext.execute();
381
+ return String(execCtx.getValue());
400
382
  }
401
383
  /**
402
384
  * Retrieves the name of the runtime where the command is executed.
@@ -409,21 +391,33 @@ class InvocationContext {
409
391
  }
410
392
  /**
411
393
  * Retrieves an array from the target runtime.
394
+ * @async
412
395
  * @returns {Promise<any[]>}
413
396
  * @method
414
397
  */
415
- retrieveArray() {
398
+ async retrieveArray() {
416
399
  const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.RetrieveArray, []);
417
400
  const localInvCtx = new InvocationContext(
418
401
  this.#runtimeName,
419
402
  this.#connectionData,
420
403
  this.#buildCommand(localCommand)
421
404
  );
422
- localInvCtx.execute();
423
- const extract = (respCommand) => {
424
- return respCommand.payload;
405
+ await localInvCtx.execute();
406
+ const resolve = (item) => {
407
+ return item?.commandType === import_CommandType.CommandType.Reference ? new InvocationContext(
408
+ this.#runtimeName,
409
+ this.#connectionData,
410
+ item
411
+ ) : item;
425
412
  };
426
- return localInvCtx.#responseCommand instanceof Promise ? localInvCtx.#responseCommand.then(extract) : localInvCtx.#responseCommand?.payload;
413
+ const respCommand = localInvCtx.#responseCommand;
414
+ if (!respCommand) {
415
+ return [];
416
+ }
417
+ if (respCommand.payload) {
418
+ return respCommand.payload.map((item) => resolve(item));
419
+ }
420
+ return respCommand.payload || [];
427
421
  }
428
422
  /**
429
423
  * Returns the primitive value from the target runtime. This could be any primitive type in JavaScript,
@@ -465,9 +459,8 @@ class InvocationContext {
465
459
  for (let i = 0; i < newArray.length; i++) {
466
460
  newArray[i] = typeof Object;
467
461
  }
468
- const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs].push(
469
- ...newArray
470
- );
462
+ const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs];
463
+ args.push(...newArray);
471
464
  return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.PassDelegate, args);
472
465
  } else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
473
466
  return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.Value, [payloadItem]);
@@ -20,6 +20,7 @@ var Javonet_exports = {};
20
20
  __export(Javonet_exports, {
21
21
  CommandDeserializer: () => import_CommandDeserializer.CommandDeserializer,
22
22
  CommandSerializer: () => import_CommandSerializer.CommandSerializer,
23
+ ComplexTypeResolver: () => import_ComplexTypeResolver.ComplexTypeResolver,
23
24
  ConfigPriority: () => import_ConfigPriority.ConfigPriority,
24
25
  Javonet: () => Javonet,
25
26
  TcpConnectionData: () => import_TcpConnectionData.TcpConnectionData,
@@ -39,6 +40,7 @@ var import_WsConnectionData = require("../utils/connectionData/WsConnectionData.
39
40
  var import_UtilsConst = require("../utils/UtilsConst.cjs");
40
41
  var import_ConfigSourceResolver = require("./configuration/ConfigSourceResolver.cjs");
41
42
  var import_ConfigPriority = require("./configuration/ConfigPriority.cjs");
43
+ var import_ComplexTypeResolver = require("./tools/ComplexTypeResolver.cjs");
42
44
  class Javonet {
43
45
  /**
44
46
  * Initializes Javonet using an in-memory channel on the same machine.
@@ -134,6 +136,7 @@ class Javonet {
134
136
  0 && (module.exports = {
135
137
  CommandDeserializer,
136
138
  CommandSerializer,
139
+ ComplexTypeResolver,
137
140
  ConfigPriority,
138
141
  Javonet,
139
142
  TcpConnectionData,
@@ -136,10 +136,11 @@ class RuntimeContext {
136
136
  * Each invocation triggers the creation of a new RuntimeContext instance wrapping the current command with a new parent command.
137
137
  * The developer can decide at any moment of the materialization for the context, taking full control of the chunks of the expression being transferred and processed on the target runtime.
138
138
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
139
+ * @returns {Promise<void>}
139
140
  * @method
140
141
  */
141
- execute() {
142
- this.#responseCommand = this.#interpreter?.execute(this.#currentCommand, this.connectionData);
142
+ async execute() {
143
+ this.#responseCommand = await this.#interpreter?.execute(this.#currentCommand, this.connectionData);
143
144
  this.#currentCommand = null;
144
145
  if (this.#responseCommand === void 0) {
145
146
  throw new Error("responseCommand is undefined in Runtime Context execute method");
@@ -154,14 +155,14 @@ class RuntimeContext {
154
155
  * The argument is a relative or full path to the library. If the library has dependencies on other libraries, the latter needs to be added first.
155
156
  * After referencing the library, any objects stored in this package can be used. Use static classes, create instances, call methods, use fields and properties, and much more.
156
157
  * @param {string} libraryPath - The relative or full path to the library.
157
- * @returns {RuntimeContext} RuntimeContext instance.
158
+ * @returns {Promise<RuntimeContext>} RuntimeContext instance.
158
159
  * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/getting-started/adding-references-to-libraries)
159
160
  * @method
160
161
  */
161
- loadLibrary(libraryPath) {
162
+ async loadLibrary(libraryPath) {
162
163
  let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.LoadLibrary, [libraryPath]);
163
164
  this.#currentCommand = this.#buildCommand(localCommand);
164
- this.execute();
165
+ await this.execute();
165
166
  return this;
166
167
  }
167
168
  /**
@@ -296,9 +297,8 @@ class RuntimeContext {
296
297
  for (let i = 0; i < newArray.length; i++) {
297
298
  newArray[i] = "object";
298
299
  }
299
- const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs].push(
300
- ...newArray
301
- );
300
+ const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs];
301
+ args.push(...newArray);
302
302
  return new import_Command.Command(this.runtimeName, import_CommandType.CommandType.PassDelegate, args);
303
303
  } else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
304
304
  return new import_Command.Command(this.runtimeName, import_CommandType.CommandType.Value, [payloadItem]);