javonet-nodejs-sdk 2.6.2 → 2.6.4

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 (172) hide show
  1. package/dist/core/handler/AbstractHandler.cjs +4 -4
  2. package/dist/core/handler/AddEventListenerHandler.cjs +36 -0
  3. package/dist/core/handler/ArrayReferenceHandler.cjs +36 -0
  4. package/dist/core/handler/AsKwargsHandler.cjs +36 -0
  5. package/dist/core/handler/AsOutHandler.cjs +36 -0
  6. package/dist/core/handler/AsRefHandler.cjs +36 -0
  7. package/dist/core/handler/CreateNullHandler.cjs +36 -0
  8. package/dist/core/handler/ExceptionHandler.cjs +36 -0
  9. package/dist/core/handler/GenerateLibHandler.cjs +36 -0
  10. package/dist/core/handler/GetAsyncOperationResultHandler.cjs +36 -0
  11. package/dist/core/handler/GetEnumItemHandler.cjs +36 -0
  12. package/dist/core/handler/GetEnumNameHandler.cjs +36 -0
  13. package/dist/core/handler/GetEnumValueHandler.cjs +36 -0
  14. package/dist/core/handler/GetGlobalFieldHandler.cjs +63 -0
  15. package/dist/core/handler/GetInstanceMethodAsDelegateHandler.cjs +2 -4
  16. package/dist/core/handler/GetModuleHandler.cjs +36 -0
  17. package/dist/core/handler/GetRefValueHandler.cjs +36 -0
  18. package/dist/core/handler/GetResultTypeHandler.cjs +43 -0
  19. package/dist/core/handler/GetStaticMethodAsDelegateHandler.cjs +4 -2
  20. package/dist/core/handler/GetTypeHandler.cjs +3 -3
  21. package/dist/core/handler/Handler.cjs +55 -11
  22. package/dist/core/handler/HeartBeatHandler.cjs +36 -0
  23. package/dist/core/handler/InvokeGenericMethodHandler.cjs +36 -0
  24. package/dist/core/handler/InvokeGenericStaticMethodHandler.cjs +36 -0
  25. package/dist/core/handler/OptimizeHandler.cjs +36 -0
  26. package/dist/core/handler/PluginWrapperHandler.cjs +36 -0
  27. package/dist/core/handler/RetrieveArrayHandler.cjs +36 -0
  28. package/dist/core/transmitter/Transmitter.cjs +4 -4
  29. package/dist/sdk/ActivatorDetails.cjs +37 -0
  30. package/dist/sdk/ConfigRuntimeFactory.cjs +50 -47
  31. package/dist/sdk/InvocationContext.cjs +91 -0
  32. package/dist/sdk/Javonet.cjs +22 -1
  33. package/dist/sdk/RuntimeContext.cjs +19 -0
  34. package/dist/sdk/RuntimeFactory.cjs +33 -1
  35. package/dist/sdk/configuration/Config.cjs +55 -0
  36. package/dist/sdk/configuration/ConfigPriority.cjs +38 -0
  37. package/dist/sdk/configuration/ConfigSourceResolver.cjs +100 -0
  38. package/dist/sdk/configuration/ConfigsDictionary.cjs +121 -0
  39. package/dist/sdk/configuration/configResolvers/ConfigResolver.cjs +121 -0
  40. package/dist/sdk/configuration/configResolvers/ConnectionStringConfigResolver.cjs +123 -0
  41. package/dist/sdk/configuration/configResolvers/JsonConfigResolver.cjs +125 -0
  42. package/dist/sdk/configuration/configResolvers/YamlConfigResolver.cjs +125 -0
  43. package/dist/sdk/tools/ComplexTypeResolver.cjs +114 -0
  44. package/dist/sdk/tools/JsonResolver.cjs +4 -1
  45. package/dist/sdk/tools/typeParsingFunctions/JavaTypeParsingFunctions.cjs +44 -0
  46. package/dist/sdk/tools/typeParsingFunctions/NetcoreTypeParsingFunctions.cjs +44 -0
  47. package/dist/sdk/tools/typeParsingFunctions/NodejsTypeParsingFunctions.cjs +44 -0
  48. package/dist/sdk/tools/typeParsingFunctions/PythonTypeParsingFunctions.cjs +44 -0
  49. package/dist/sdk/tools/typeParsingFunctions/TypeParsingUtils.cjs +34 -0
  50. package/dist/types/core/handler/AddEventListenerHandler.d.ts +7 -0
  51. package/dist/types/core/handler/ArrayReferenceHandler.d.ts +7 -0
  52. package/dist/types/core/handler/AsKwargsHandler.d.ts +7 -0
  53. package/dist/types/core/handler/AsOutHandler.d.ts +7 -0
  54. package/dist/types/core/handler/AsRefHandler.d.ts +7 -0
  55. package/dist/types/core/handler/CreateNullHandler.d.ts +7 -0
  56. package/dist/types/core/handler/ExceptionHandler.d.ts +7 -0
  57. package/dist/types/core/handler/GenerateLibHandler.d.ts +7 -0
  58. package/dist/types/core/handler/GetAsyncOperationResultHandler.d.ts +7 -0
  59. package/dist/types/core/handler/GetEnumItemHandler.d.ts +7 -0
  60. package/dist/types/core/handler/GetEnumNameHandler.d.ts +7 -0
  61. package/dist/types/core/handler/GetEnumValueHandler.d.ts +7 -0
  62. package/dist/types/core/handler/GetGlobalFieldHandler.d.ts +13 -0
  63. package/dist/types/core/handler/GetModuleHandler.d.ts +7 -0
  64. package/dist/types/core/handler/GetRefValueHandler.d.ts +7 -0
  65. package/dist/types/core/handler/GetResultTypeHandler.d.ts +18 -0
  66. package/dist/types/core/handler/HeartBeatHandler.d.ts +7 -0
  67. package/dist/types/core/handler/InvokeGenericMethodHandler.d.ts +7 -0
  68. package/dist/types/core/handler/InvokeGenericStaticMethodHandler.d.ts +7 -0
  69. package/dist/types/core/handler/OptimizeHandler.d.ts +7 -0
  70. package/dist/types/core/handler/PluginWrapperHandler.d.ts +7 -0
  71. package/dist/types/core/handler/RetrieveArrayHandler.d.ts +7 -0
  72. package/dist/types/core/transmitter/Transmitter.d.ts +1 -1
  73. package/dist/types/sdk/ActivatorDetails.d.ts +12 -0
  74. package/dist/types/sdk/ConfigRuntimeFactory.d.ts +3 -0
  75. package/dist/types/sdk/InvocationContext.d.ts +22 -0
  76. package/dist/types/sdk/Javonet.d.ts +15 -1
  77. package/dist/types/sdk/RuntimeContext.d.ts +8 -0
  78. package/dist/types/sdk/RuntimeFactory.d.ts +14 -0
  79. package/dist/types/sdk/configuration/Config.d.ts +14 -0
  80. package/dist/types/sdk/configuration/ConfigPriority.d.ts +8 -0
  81. package/dist/types/sdk/configuration/ConfigSourceResolver.d.ts +7 -0
  82. package/dist/types/sdk/configuration/ConfigsDictionary.d.ts +30 -0
  83. package/dist/types/sdk/configuration/configResolvers/ConfigResolver.d.ts +30 -0
  84. package/dist/types/sdk/configuration/configResolvers/ConnectionStringConfigResolver.d.ts +23 -0
  85. package/dist/types/sdk/configuration/configResolvers/JsonConfigResolver.d.ts +26 -0
  86. package/dist/types/sdk/configuration/configResolvers/YamlConfigResolver.d.ts +32 -0
  87. package/dist/types/sdk/tools/ComplexTypeResolver.d.ts +28 -0
  88. package/dist/types/sdk/tools/JsonResolver.d.ts +4 -2
  89. package/dist/types/sdk/tools/typeParsingFunctions/JavaTypeParsingFunctions.d.ts +11 -0
  90. package/dist/types/sdk/tools/typeParsingFunctions/NetcoreTypeParsingFunctions.d.ts +11 -0
  91. package/dist/types/sdk/tools/typeParsingFunctions/NodejsTypeParsingFunctions.d.ts +11 -0
  92. package/dist/types/sdk/tools/typeParsingFunctions/PythonTypeParsingFunctions.d.ts +11 -0
  93. package/dist/types/sdk/tools/typeParsingFunctions/TypeParsingUtils.d.ts +1 -0
  94. package/dist/types/utils/CommandType.d.ts +3 -0
  95. package/dist/types/utils/IsThenable.d.ts +6 -0
  96. package/dist/types/utils/Runtime.d.ts +4 -3
  97. package/dist/types/utils/RuntimeNameHandler.d.ts +5 -0
  98. package/dist/utils/CommandType.cjs +4 -1
  99. package/dist/utils/IsThenable.cjs +30 -0
  100. package/dist/utils/RuntimeNameHandler.cjs +34 -0
  101. package/dist/utils/connectionData/InMemoryConnectionData.cjs +7 -1
  102. package/dist/utils/connectionData/WsConnectionData.cjs +6 -0
  103. package/dist/utils/exception/ExceptionSerializer.cjs +6 -2
  104. package/dist/utils/nodejs/connectionData/TcpConnectionData.cjs +15 -6
  105. package/lib/core/handler/AbstractHandler.js +7 -5
  106. package/lib/core/handler/AddEventListenerHandler.js +11 -0
  107. package/lib/core/handler/ArrayReferenceHandler.js +11 -0
  108. package/lib/core/handler/AsKwargsHandler.js +11 -0
  109. package/lib/core/handler/AsOutHandler.js +11 -0
  110. package/lib/core/handler/AsRefHandler.js +11 -0
  111. package/lib/core/handler/CreateNullHandler.js +11 -0
  112. package/lib/core/handler/ExceptionHandler.js +11 -0
  113. package/lib/core/handler/GenerateLibHandler.js +11 -0
  114. package/lib/core/handler/GetAsyncOperationResultHandler.js +11 -0
  115. package/lib/core/handler/GetEnumItemHandler.js +11 -0
  116. package/lib/core/handler/GetEnumNameHandler.js +11 -0
  117. package/lib/core/handler/GetEnumValueHandler.js +11 -0
  118. package/lib/core/handler/GetGlobalFieldHandler.js +44 -0
  119. package/lib/core/handler/GetInstanceMethodAsDelegateHandler.js +3 -3
  120. package/lib/core/handler/GetModuleHandler.js +11 -0
  121. package/lib/core/handler/GetRefValueHandler.js +11 -0
  122. package/lib/core/handler/GetResultTypeHandler.js +29 -0
  123. package/lib/core/handler/GetStaticFieldHandler.js +0 -1
  124. package/lib/core/handler/GetStaticMethodAsDelegateHandler.js +3 -1
  125. package/lib/core/handler/GetTypeHandler.js +3 -3
  126. package/lib/core/handler/Handler.js +55 -11
  127. package/lib/core/handler/HeartBeatHandler.js +11 -0
  128. package/lib/core/handler/InvokeGenericMethodHandler.js +11 -0
  129. package/lib/core/handler/InvokeGenericStaticMethodHandler.js +11 -0
  130. package/lib/core/handler/InvokeStaticMethodHandler.js +1 -1
  131. package/lib/core/handler/OptimizeHandler.js +11 -0
  132. package/lib/core/handler/PluginWrapperHandler.js +11 -0
  133. package/lib/core/handler/ResolveReferenceHandler.js +1 -3
  134. package/lib/core/handler/RetrieveArrayHandler.js +11 -0
  135. package/lib/core/receiver/Receiver.js +5 -7
  136. package/lib/core/transmitter/Transmitter.js +5 -5
  137. package/lib/core/webSocketClient/WebSocketClientBrowser.js +2 -2
  138. package/lib/sdk/ActivatorDetails.js +15 -0
  139. package/lib/sdk/ConfigRuntimeFactory.js +65 -48
  140. package/lib/sdk/InvocationContext.js +95 -0
  141. package/lib/sdk/Javonet.js +31 -3
  142. package/lib/sdk/RuntimeContext.js +21 -0
  143. package/lib/sdk/RuntimeFactory.js +49 -1
  144. package/lib/sdk/configuration/Config.js +37 -0
  145. package/lib/sdk/configuration/ConfigPriority.js +9 -0
  146. package/lib/sdk/configuration/ConfigSourceResolver.js +84 -0
  147. package/lib/sdk/configuration/ConfigsDictionary.js +118 -0
  148. package/lib/sdk/configuration/configResolvers/ConfigResolver.js +109 -0
  149. package/lib/sdk/configuration/configResolvers/ConnectionStringConfigResolver.js +119 -0
  150. package/lib/sdk/configuration/configResolvers/JsonConfigResolver.js +99 -0
  151. package/lib/sdk/configuration/configResolvers/YamlConfigResolver.js +109 -0
  152. package/lib/sdk/tools/ActivationHelper.js +1 -1
  153. package/lib/sdk/tools/ComplexTypeResolver.js +103 -0
  154. package/lib/sdk/tools/JsonResolver.js +5 -1
  155. package/lib/sdk/tools/typeParsingFunctions/JavaTypeParsingFunctions.js +25 -0
  156. package/lib/sdk/tools/typeParsingFunctions/NetcoreTypeParsingFunctions.js +25 -0
  157. package/lib/sdk/tools/typeParsingFunctions/NodejsTypeParsingFunctions.js +25 -0
  158. package/lib/sdk/tools/typeParsingFunctions/PythonTypeParsingFunctions.js +25 -0
  159. package/lib/sdk/tools/typeParsingFunctions/TypeParsingUtils.js +13 -0
  160. package/lib/utils/CommandType.js +3 -0
  161. package/lib/utils/CustomError.js +1 -1
  162. package/lib/utils/IsThenable.js +10 -0
  163. package/lib/utils/Runtime.js +11 -4
  164. package/lib/utils/RuntimeLoggerBrowser.js +0 -1
  165. package/lib/utils/RuntimeNameHandler.js +37 -0
  166. package/lib/utils/TypesHandler.js +11 -5
  167. package/lib/utils/connectionData/InMemoryConnectionData.js +8 -1
  168. package/lib/utils/connectionData/WsConnectionData.js +7 -0
  169. package/lib/utils/exception/ExceptionSerializer.js +6 -2
  170. package/lib/utils/nodejs/connectionData/TcpConnectionData.js +16 -6
  171. package/lib/utils/nodejs/uuid/v4.js +0 -1
  172. package/package.json +4 -2
@@ -373,6 +373,34 @@ class InvocationContext {
373
373
  ]);
374
374
  return this.#createInstanceContext(localCommand);
375
375
  }
376
+ /**
377
+ * Retrieves the type of the object from the target runtime.
378
+ * @returns {string} The type of the object.
379
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
380
+ * @method
381
+ */
382
+ getResultType() {
383
+ const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
384
+ const invocationContext = new InvocationContext(
385
+ this.#runtimeName,
386
+ this.#connectionData,
387
+ this.#buildCommand(localCommand)
388
+ );
389
+ const result = invocationContext.execute().getValue();
390
+ return (
391
+ /** @type {string} */
392
+ result
393
+ );
394
+ }
395
+ /**
396
+ * Retrieves the name of the runtime where the command is executed.
397
+ * @returns {number} The name of the runtime.
398
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/runtime-name)
399
+ * @method
400
+ */
401
+ getRuntimeName() {
402
+ return this.#runtimeName;
403
+ }
376
404
  /**
377
405
  * Retrieves an array from the target runtime.
378
406
  * @returns {InvocationContext} A new InvocationContext instance that wraps the command to retrieve the array.
@@ -517,6 +545,69 @@ class InvocationWsContext extends InvocationContext {
517
545
  }
518
546
  return new InvocationWsContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true);
519
547
  }
548
+ /**
549
+ * Retrieves the type of the object from the target runtime.
550
+ * @returns {Promise<string>} The type of the object.
551
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
552
+ * @async
553
+ * @method
554
+ */
555
+ // @ts-expect-error
556
+ async getResultType() {
557
+ const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
558
+ const invocationContext = new InvocationWsContext(
559
+ this.#runtimeName,
560
+ this.#connectionData,
561
+ this.#buildCommand(localCommand)
562
+ );
563
+ const result = await invocationContext.execute();
564
+ return (
565
+ /** @type {string} */
566
+ result.getValue()
567
+ );
568
+ }
569
+ /**
570
+ * @param {Command} command
571
+ * @returns {Command}
572
+ */
573
+ #buildCommand(command) {
574
+ for (let i = 0; i < command.payload.length; i++) {
575
+ command.payload[i] = this.#encapsulatePayloadItem(command.payload[i]);
576
+ }
577
+ return command.prependArgToPayload(this.#currentCommand);
578
+ }
579
+ /**
580
+ * @param {unknown} payloadItem
581
+ * @returns {Command|null}
582
+ */
583
+ #encapsulatePayloadItem(payloadItem) {
584
+ if (payloadItem instanceof import_Command.Command) {
585
+ for (let i = 0; i < payloadItem.payload.length; i++) {
586
+ payloadItem.payload[i] = this.#encapsulatePayloadItem(payloadItem.payload[i]);
587
+ }
588
+ return payloadItem;
589
+ } else if (payloadItem instanceof InvocationContext || payloadItem instanceof InvocationWsContext) {
590
+ return payloadItem.get_current_command();
591
+ } else if (payloadItem instanceof Array) {
592
+ const copiedArray = payloadItem.map((item) => this.#encapsulatePayloadItem(item));
593
+ return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.Array, copiedArray);
594
+ } else if (typeof payloadItem === "function") {
595
+ let newArray = new Array(payloadItem.length + 1);
596
+ for (let i = 0; i < newArray.length; i++) {
597
+ newArray[i] = typeof Object;
598
+ }
599
+ const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs].push(
600
+ ...newArray
601
+ );
602
+ return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.PassDelegate, args);
603
+ } else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
604
+ return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.Value, [payloadItem]);
605
+ } else {
606
+ throw Error(
607
+ "Unsupported payload item type: " + (payloadItem?.constructor?.name || typeof payloadItem) + " for payload item: " + payloadItem
608
+ );
609
+ }
610
+ }
520
611
  }
521
612
  // Annotate the CommonJS export names for ESM import in node:
522
613
  0 && (module.exports = {
@@ -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
+ ConfigPriority: () => import_ConfigPriority.ConfigPriority,
23
24
  Javonet: () => Javonet,
24
25
  TcpConnectionData: () => import_TcpConnectionData.TcpConnectionData,
25
26
  WsConnectionData: () => import_WsConnectionData.WsConnectionData
@@ -27,6 +28,7 @@ __export(Javonet_exports, {
27
28
  module.exports = __toCommonJS(Javonet_exports);
28
29
  var import_ConfigRuntimeFactory = require("./ConfigRuntimeFactory.cjs");
29
30
  var import_RuntimeFactory = require("./RuntimeFactory.cjs");
31
+ var import_RuntimeContext = require("./RuntimeContext.cjs");
30
32
  var import_InMemoryConnectionData = require("../utils/connectionData/InMemoryConnectionData.cjs");
31
33
  var import_Runtime = require("../utils/Runtime.cjs");
32
34
  var import_CommandSerializer = require("../core/protocol/CommandSerializer.cjs");
@@ -34,8 +36,9 @@ var import_CommandDeserializer = require("../core/protocol/CommandDeserializer.c
34
36
  var import_RuntimeLogger = require("../utils/RuntimeLogger.cjs");
35
37
  var import_TcpConnectionData = require("../utils/nodejs/connectionData/TcpConnectionData.cjs");
36
38
  var import_WsConnectionData = require("../utils/connectionData/WsConnectionData.cjs");
37
- var import_ActivationHelper = require("./tools/ActivationHelper.cjs");
38
39
  var import_UtilsConst = require("../utils/UtilsConst.cjs");
40
+ var import_ConfigSourceResolver = require("./configuration/ConfigSourceResolver.cjs");
41
+ var import_ConfigPriority = require("./configuration/ConfigPriority.cjs");
39
42
  const import_meta = {};
40
43
  const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
41
44
  let _Transmitter = null;
@@ -120,11 +123,29 @@ class Javonet {
120
123
  static setJavonetWorkingDirectory(path) {
121
124
  import_UtilsConst.UtilsConst.setJavonetWorkingDirectory(path);
122
125
  }
126
+ /**
127
+ * Adds a configuration to the ConfigSourceResolver with the specified priority and source.
128
+ * @param {number} priority - The priority of the configuration.
129
+ * @param {string} configSource - The configuration source.
130
+ */
131
+ static addConfig(priority, configSource) {
132
+ import_ConfigSourceResolver.ConfigSourceResolver.addConfigs(priority, configSource);
133
+ }
134
+ /**
135
+ * Initializes a RuntimeContext instance based on the specified configuration name.
136
+ * @param {string} configName - The name of the configuration to use.
137
+ * @returns {RuntimeContext} A RuntimeContext instance initialized with the specified configuration.
138
+ */
139
+ static initializeRc(configName) {
140
+ const config = import_ConfigSourceResolver.ConfigSourceResolver.getConfig(configName);
141
+ return import_RuntimeFactory.RuntimeFactory.initializeRuntimeContext(config);
142
+ }
123
143
  }
124
144
  // Annotate the CommonJS export names for ESM import in node:
125
145
  0 && (module.exports = {
126
146
  CommandDeserializer,
127
147
  CommandSerializer,
148
+ ConfigPriority,
128
149
  Javonet,
129
150
  TcpConnectionData,
130
151
  WsConnectionData
@@ -264,6 +264,25 @@ class RuntimeContext {
264
264
  }
265
265
  return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
266
266
  }
267
+ /**
268
+ * Retrieves the value of an global field from the target runtime.
269
+ * @param {string} fieldName - The name of the field to get.
270
+ * @returns {InvocationContext} A new InvocationContext instance that wraps the command to get the global field.
271
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/fields-and-properties/getting-values-for-global-fields)
272
+ * @method
273
+ */
274
+ getGlobalField(fieldName) {
275
+ let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.GetGlobalField, [fieldName]);
276
+ 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
+ return new import_InvocationContext.InvocationContext(this.runtimeName, this.connectionData, this.#buildCommand(localCommand));
285
+ }
267
286
  /**
268
287
  * Invokes a function from the called runtime. This method is used when working with functions from the called runtime.
269
288
  * The arguments include the function name and the arguments to be passed to the function.
@@ -25,7 +25,7 @@ var import_RuntimeName = require("../utils/RuntimeName.cjs");
25
25
  var import_RuntimeContext = require("./RuntimeContext.cjs");
26
26
  class RuntimeFactory {
27
27
  /**
28
- * @param {IConnectionData} connectionData
28
+ * @param {IConnectionData} connectionData
29
29
  */
30
30
  constructor(connectionData) {
31
31
  this.connectionData = connectionData;
@@ -86,6 +86,14 @@ class RuntimeFactory {
86
86
  nodejs() {
87
87
  return import_RuntimeContext.RuntimeContext.getInstance(import_RuntimeName.RuntimeName.Nodejs, this.connectionData);
88
88
  }
89
+ /**
90
+ * Creates RuntimeContext instance to interact with the PHP runtime.
91
+ * @return {RuntimeContext} a RuntimeContext instance for the PHP runtime
92
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
93
+ */
94
+ php() {
95
+ return import_RuntimeContext.RuntimeContext.getInstance(import_RuntimeName.RuntimeName.Php, this.connectionData);
96
+ }
89
97
  /**
90
98
  * Creates RuntimeContext instance to interact with the Python runtime.
91
99
  * @return {RuntimeContext} a RuntimeContext instance for the Python runtime
@@ -94,6 +102,30 @@ class RuntimeFactory {
94
102
  python27() {
95
103
  return import_RuntimeContext.RuntimeContext.getInstance(import_RuntimeName.RuntimeName.Python27, this.connectionData);
96
104
  }
105
+ /**
106
+ * @param {{ runtime: import("../types.js").RuntimeName; connectionData: import("../utils/connectionData/IConnectionData.js").IConnectionData; modules: any; }} config
107
+ */
108
+ static initializeRuntimeContext(config) {
109
+ const rtmCtx = import_RuntimeContext.RuntimeContext.getInstance(config.runtime, config.connectionData);
110
+ const modules = (config.modules || "").split(",").map((m) => m.trim()).filter((m) => m !== "");
111
+ let pathModule = null;
112
+ try {
113
+ const _require = typeof require !== "undefined" ? require : eval("require");
114
+ pathModule = _require("path");
115
+ } catch (e) {
116
+ pathModule = null;
117
+ }
118
+ modules.forEach((module2) => {
119
+ const isAbsolute = pathModule ? pathModule.isAbsolute(module2) : module2.startsWith("/") || /^[A-Za-z]:\\/.test(module2);
120
+ if (isAbsolute) {
121
+ rtmCtx.loadLibrary(module2);
122
+ } else {
123
+ const resolved = pathModule ? pathModule.join(process.cwd(), module2) : `${process.cwd()}/${module2}`;
124
+ rtmCtx.loadLibrary(resolved);
125
+ }
126
+ });
127
+ return rtmCtx;
128
+ }
97
129
  }
98
130
  // Annotate the CommonJS export names for ESM import in node:
99
131
  0 && (module.exports = {
@@ -0,0 +1,55 @@
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 Config_exports = {};
20
+ __export(Config_exports, {
21
+ Config: () => Config
22
+ });
23
+ module.exports = __toCommonJS(Config_exports);
24
+ class Config {
25
+ /**
26
+ * @param {*} runtime
27
+ * @param {*} connectionData
28
+ * @param {string} [plugins=""]
29
+ * @param {string} [modules=""]
30
+ */
31
+ constructor(runtime, connectionData, plugins = "", modules = "") {
32
+ this.runtime = runtime;
33
+ this.connectionData = connectionData;
34
+ this.plugins = plugins ?? "";
35
+ this.modules = modules ?? "";
36
+ }
37
+ toString() {
38
+ const parts = [];
39
+ parts.push(`Runtime: ${this.runtime}`);
40
+ if (this.connectionData != null) {
41
+ parts.push(`Host: ${this.connectionData}`);
42
+ }
43
+ if (String(this.plugins).trim()) {
44
+ parts.push(`Plugins: ${this.plugins}`);
45
+ }
46
+ if (String(this.modules).trim()) {
47
+ parts.push(`Modules: ${this.modules}`);
48
+ }
49
+ return parts.join(", ");
50
+ }
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ Config
55
+ });
@@ -0,0 +1,38 @@
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 ConfigPriority_exports = {};
20
+ __export(ConfigPriority_exports, {
21
+ ConfigPriority: () => ConfigPriority
22
+ });
23
+ module.exports = __toCommonJS(ConfigPriority_exports);
24
+ const ConfigPriority = (
25
+ /** @type {const} */
26
+ {
27
+ RuntimeSpecificEnv: 1,
28
+ GlobalEnv: 2,
29
+ RuntimeSpecificFile: 3,
30
+ GlobalFile: 4,
31
+ User: 5,
32
+ DefaultLibrary: 6
33
+ }
34
+ );
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ ConfigPriority
38
+ });
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ConfigSourceResolver_exports = {};
30
+ __export(ConfigSourceResolver_exports, {
31
+ ConfigSourceResolver: () => ConfigSourceResolver
32
+ });
33
+ module.exports = __toCommonJS(ConfigSourceResolver_exports);
34
+ var import_fs = __toESM(require("fs"), 1);
35
+ var import_process = __toESM(require("process"), 1);
36
+ var import_ConfigsDictionary = require("./ConfigsDictionary.cjs");
37
+ var import_JsonConfigResolver = require("./configResolvers/JsonConfigResolver.cjs");
38
+ var import_YamlConfigResolver = require("./configResolvers/YamlConfigResolver.cjs");
39
+ var import_ConnectionStringConfigResolver = require("./configResolvers/ConnectionStringConfigResolver.cjs");
40
+ class ConfigSourceResolver {
41
+ static addConfigs(priority, configSource) {
42
+ console.log(`Adding config from source: ${configSource} with priority '${priority}'`);
43
+ const configString = ConfigSourceResolver._getConfigSourceAsString(configSource);
44
+ ConfigSourceResolver._parseConfigsAndAddToCollection(priority, configString);
45
+ }
46
+ static getConfig(configName) {
47
+ console.log(`Retrieving config ${configName}`);
48
+ return import_ConfigsDictionary.ConfigsDictionary.getConfig(configName);
49
+ }
50
+ static clearConfigs() {
51
+ import_ConfigsDictionary.ConfigsDictionary.clearConfigs();
52
+ }
53
+ static _getConfigSourceAsString(configSource) {
54
+ if (!configSource || configSource.trim() === "") {
55
+ throw new Error("Config source cannot be null or whitespace.");
56
+ }
57
+ const envValue = import_process.default.env[configSource];
58
+ if (envValue && envValue.trim() !== "") {
59
+ configSource = envValue;
60
+ }
61
+ if (import_fs.default.existsSync(configSource) && import_fs.default.statSync(configSource).isFile()) {
62
+ configSource = import_fs.default.readFileSync(configSource, { encoding: "utf-8" });
63
+ }
64
+ return configSource.trim();
65
+ }
66
+ static _parseConfigsAndAddToCollection(priority, configString) {
67
+ try {
68
+ const jsonObject = JSON.parse(configString);
69
+ import_JsonConfigResolver.JsonConfigResolver.addConfigs(priority, jsonObject);
70
+ return;
71
+ } catch (ex) {
72
+ if (ex instanceof SyntaxError) {
73
+ } else {
74
+ console.log("Failed to parse config source as JSON: " + ex);
75
+ }
76
+ }
77
+ try {
78
+ import_YamlConfigResolver.YamlConfigResolver.addConfigs(priority, configString);
79
+ return;
80
+ } catch (ex) {
81
+ if (ex.name === "SyntaxError") {
82
+ } else {
83
+ console.log("Failed to parse config source as YAML: " + ex);
84
+ }
85
+ }
86
+ try {
87
+ import_ConnectionStringConfigResolver.ConnectionStringConfigResolver.addConfigs(priority, configString);
88
+ return;
89
+ } catch (ex) {
90
+ console.log("Failed to parse config source as connection string: " + ex);
91
+ }
92
+ throw new Error(
93
+ "Config source is not valid JSON, YAML, or connection string format:\n" + configString
94
+ );
95
+ }
96
+ }
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ ConfigSourceResolver
100
+ });
@@ -0,0 +1,121 @@
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 ConfigsDictionary_exports = {};
20
+ __export(ConfigsDictionary_exports, {
21
+ ConfigsDictionary: () => ConfigsDictionary
22
+ });
23
+ module.exports = __toCommonJS(ConfigsDictionary_exports);
24
+ class ConfigsDictionary {
25
+ /** @type {Map<string, Map<number, any>>} */
26
+ static _configurations_collection = /* @__PURE__ */ new Map();
27
+ /**
28
+ * Normalize priority to a numeric value.
29
+ * Accepts either a number or an object with a numeric `value` property.
30
+ * @param {any} priority
31
+ * @returns {number|undefined}
32
+ */
33
+ static _normalizePriority(priority) {
34
+ if (typeof priority === "number" && Number.isFinite(priority)) {
35
+ return priority;
36
+ }
37
+ if (priority && typeof priority === "object" && "value" in priority && typeof priority.value === "number") {
38
+ return priority.value;
39
+ }
40
+ return void 0;
41
+ }
42
+ /**
43
+ * Add a configuration for a given name and priority.
44
+ * If the same name+priority already exists, it will not be overwritten.
45
+ * @param {string} name
46
+ * @param {number|{value:number}} priority
47
+ * @param {*} config
48
+ */
49
+ static addConfig(name, priority, config) {
50
+ if (!name || String(name).trim() === "") {
51
+ console.log("Config name cannot be null or whitespace. Skipping add.");
52
+ return;
53
+ }
54
+ if (config == null) {
55
+ console.log("Config instance is null. Skipping add.");
56
+ return;
57
+ }
58
+ const key = ConfigsDictionary._normalizePriority(priority);
59
+ if (typeof key !== "number") {
60
+ console.log(
61
+ "Priority must be a numeric value or an object with a numeric `value` property. Skipping add."
62
+ );
63
+ return;
64
+ }
65
+ let perPriority = ConfigsDictionary._configurations_collection.get(name);
66
+ if (!perPriority) {
67
+ perPriority = /* @__PURE__ */ new Map();
68
+ ConfigsDictionary._configurations_collection.set(name, perPriority);
69
+ }
70
+ if (perPriority.has(key)) {
71
+ console.log(
72
+ `Config with name \`${name}\` and priority \`${key}\` already exists. It will not be added or updated.`
73
+ );
74
+ return;
75
+ }
76
+ perPriority.set(key, config);
77
+ let serialized;
78
+ try {
79
+ serialized = JSON.stringify(config);
80
+ } catch {
81
+ serialized = String(config);
82
+ }
83
+ console.log(`Added configuration \`${name}\` with priority \`${key}\` and parameters ${serialized}`);
84
+ }
85
+ /**
86
+ * Retrieve the configuration with the numerically smallest priority for the given name.
87
+ * Throws if name is invalid or no configuration is found.
88
+ * @param {string} name
89
+ * @returns {*}
90
+ */
91
+ static getConfig(name) {
92
+ if (!name || String(name).trim() === "") {
93
+ throw new Error("Config name cannot be null or whitespace");
94
+ }
95
+ const perPriority = ConfigsDictionary._configurations_collection.get(name);
96
+ if (!perPriority || perPriority.size === 0) {
97
+ throw new Error(`Configuration ${name} not found`);
98
+ }
99
+ const keysArray = [...perPriority.keys()];
100
+ const smallest = keysArray.reduce((min, k) => k < min ? k : min, keysArray[0]);
101
+ const config = perPriority.get(smallest);
102
+ let serialized;
103
+ try {
104
+ serialized = JSON.stringify(config);
105
+ } catch {
106
+ serialized = String(config);
107
+ }
108
+ console.log(
109
+ `Retrieved configuration \`${name}\` with priority \`${smallest}\` and parameters ${serialized}`
110
+ );
111
+ return config;
112
+ }
113
+ /** Clear all stored configurations. */
114
+ static clearConfigs() {
115
+ ConfigsDictionary._configurations_collection.clear();
116
+ }
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ ConfigsDictionary
121
+ });
@@ -0,0 +1,121 @@
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 ConfigResolver_exports = {};
20
+ __export(ConfigResolver_exports, {
21
+ ConfigResolver: () => ConfigResolver
22
+ });
23
+ module.exports = __toCommonJS(ConfigResolver_exports);
24
+ var import_RuntimeNameHandler = require("../../../utils/RuntimeNameHandler.cjs");
25
+ var import_InMemoryConnectionData = require("../../../utils/connectionData/InMemoryConnectionData.cjs");
26
+ var import_WsConnectionData = require("../../../utils/connectionData/WsConnectionData.cjs");
27
+ var import_TcpConnectionData = require("../../../utils/nodejs/connectionData/TcpConnectionData.cjs");
28
+ class ConfigResolver {
29
+ /**
30
+ * Parse a runtime string into the runtime enum/name using RuntimeNameHandler.
31
+ * @param {string} runtime
32
+ * @returns {*}
33
+ */
34
+ static tryParseRuntime(runtime) {
35
+ if (!runtime || String(runtime).trim() === "") {
36
+ throw new Error("Runtime string cannot be null or whitespace.");
37
+ }
38
+ const normalized = String(runtime).trim().toLowerCase();
39
+ return import_RuntimeNameHandler.RuntimeNameHandler.getRuntime(normalized);
40
+ }
41
+ /**
42
+ * Build appropriate connection data object from a host string.
43
+ * - empty / null => InMemoryConnectionData
44
+ * - "inmemory" or "in-memory" => InMemoryConnectionData
45
+ * - ws:// or wss:// => WsConnectionData(fullAddress)
46
+ * - tcp://... => parsed by parseTcp
47
+ * - host:port or host:port/... => TcpConnectionData(host, port) if valid, otherwise InMemoryConnectionData
48
+ * @param {string} hostValue
49
+ * @returns {InMemoryConnectionData|WsConnectionData|TcpConnectionData}
50
+ */
51
+ static buildConnectionData(hostValue) {
52
+ if (!hostValue || String(hostValue).trim() === "") {
53
+ return new import_InMemoryConnectionData.InMemoryConnectionData();
54
+ }
55
+ const hv = String(hostValue).trim();
56
+ const lower = hv.toLowerCase();
57
+ if (lower === "inmemory" || lower === "in-memory") {
58
+ return new import_InMemoryConnectionData.InMemoryConnectionData();
59
+ }
60
+ if (lower.startsWith("ws://") || lower.startsWith("wss://")) {
61
+ return new import_WsConnectionData.WsConnectionData(hv);
62
+ }
63
+ if (lower.startsWith("tcp://")) {
64
+ try {
65
+ return ConfigResolver.parseTcp(hv.slice(6));
66
+ } catch (e) {
67
+ return new import_InMemoryConnectionData.InMemoryConnectionData();
68
+ }
69
+ }
70
+ const colon = hv.indexOf(":");
71
+ if (colon > 0 && colon < hv.length - 1) {
72
+ let portPart = hv.substring(colon + 1);
73
+ const slash = portPart.indexOf("/");
74
+ if (slash >= 0) {
75
+ portPart = portPart.substring(0, slash);
76
+ }
77
+ try {
78
+ const port = parseInt(portPart, 10);
79
+ if (!Number.isFinite(port) || Number.isNaN(port)) {
80
+ throw new Error("invalid port");
81
+ }
82
+ const hostOnly = hv.substring(0, colon);
83
+ if (String(hostOnly).trim()) {
84
+ try {
85
+ return new import_TcpConnectionData.TcpConnectionData(hostOnly, port);
86
+ } catch (e) {
87
+ return new import_InMemoryConnectionData.InMemoryConnectionData();
88
+ }
89
+ }
90
+ } catch (e) {
91
+ }
92
+ }
93
+ return new import_InMemoryConnectionData.InMemoryConnectionData();
94
+ }
95
+ /**
96
+ * Parse tcp address portion (after tcp://) into TcpConnectionData.
97
+ * Expected formats: host:port or host:port/...
98
+ * Throws Error on invalid format or port.
99
+ * @param {string} address
100
+ * @returns {TcpConnectionData}
101
+ */
102
+ static parseTcp(address) {
103
+ const slash = address.indexOf("/");
104
+ const hostPort = slash >= 0 ? address.substring(0, slash) : address;
105
+ const colon = hostPort.lastIndexOf(":");
106
+ if (colon <= 0 || colon >= hostPort.length - 1) {
107
+ throw new Error("Invalid tcp:// format.");
108
+ }
109
+ const host = hostPort.substring(0, colon);
110
+ const portStr = hostPort.substring(colon + 1);
111
+ const port = parseInt(portStr, 10);
112
+ if (!Number.isFinite(port) || Number.isNaN(port)) {
113
+ throw new Error("Invalid port in tcp:// address.");
114
+ }
115
+ return new import_TcpConnectionData.TcpConnectionData(host, port);
116
+ }
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ ConfigResolver
121
+ });