javonet-nodejs-sdk 2.6.3 → 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 (99) hide show
  1. package/dist/core/handler/AbstractHandler.cjs +4 -4
  2. package/dist/core/handler/GetInstanceMethodAsDelegateHandler.cjs +2 -4
  3. package/dist/core/handler/GetStaticMethodAsDelegateHandler.cjs +4 -2
  4. package/dist/core/handler/GetTypeHandler.cjs +3 -3
  5. package/dist/core/transmitter/Transmitter.cjs +4 -4
  6. package/dist/sdk/ConfigRuntimeFactory.cjs +50 -47
  7. package/dist/sdk/InvocationContext.cjs +10 -2
  8. package/dist/sdk/Javonet.cjs +22 -0
  9. package/dist/sdk/RuntimeFactory.cjs +33 -1
  10. package/dist/sdk/configuration/Config.cjs +55 -0
  11. package/dist/sdk/configuration/ConfigPriority.cjs +38 -0
  12. package/dist/sdk/configuration/ConfigSourceResolver.cjs +100 -0
  13. package/dist/sdk/configuration/ConfigsDictionary.cjs +121 -0
  14. package/dist/sdk/configuration/configResolvers/ConfigResolver.cjs +121 -0
  15. package/dist/sdk/configuration/configResolvers/ConnectionStringConfigResolver.cjs +123 -0
  16. package/dist/sdk/configuration/configResolvers/JsonConfigResolver.cjs +125 -0
  17. package/dist/sdk/configuration/configResolvers/YamlConfigResolver.cjs +125 -0
  18. package/dist/sdk/tools/JsonResolver.cjs +4 -1
  19. package/dist/types/core/transmitter/Transmitter.d.ts +1 -1
  20. package/dist/types/sdk/ConfigRuntimeFactory.d.ts +3 -0
  21. package/dist/types/sdk/Javonet.d.ts +15 -1
  22. package/dist/types/sdk/RuntimeFactory.d.ts +14 -0
  23. package/dist/types/sdk/configuration/Config.d.ts +14 -0
  24. package/dist/types/sdk/configuration/ConfigPriority.d.ts +8 -0
  25. package/dist/types/sdk/configuration/ConfigSourceResolver.d.ts +7 -0
  26. package/dist/types/sdk/configuration/ConfigsDictionary.d.ts +30 -0
  27. package/dist/types/sdk/configuration/configResolvers/ConfigResolver.d.ts +30 -0
  28. package/dist/types/sdk/configuration/configResolvers/ConnectionStringConfigResolver.d.ts +23 -0
  29. package/dist/types/sdk/configuration/configResolvers/JsonConfigResolver.d.ts +26 -0
  30. package/dist/types/sdk/configuration/configResolvers/YamlConfigResolver.d.ts +32 -0
  31. package/dist/types/sdk/tools/JsonResolver.d.ts +4 -2
  32. package/dist/types/utils/Runtime.d.ts +4 -3
  33. package/dist/types/utils/RuntimeNameHandler.d.ts +5 -0
  34. package/dist/utils/RuntimeNameHandler.cjs +34 -0
  35. package/dist/utils/connectionData/InMemoryConnectionData.cjs +7 -1
  36. package/dist/utils/connectionData/WsConnectionData.cjs +6 -0
  37. package/dist/utils/exception/ExceptionSerializer.cjs +6 -2
  38. package/dist/utils/nodejs/connectionData/TcpConnectionData.cjs +15 -6
  39. package/lib/core/handler/AbstractHandler.js +7 -5
  40. package/lib/core/handler/AddEventListenerHandler.js +2 -3
  41. package/lib/core/handler/ArrayReferenceHandler.js +2 -3
  42. package/lib/core/handler/AsKwargsHandler.js +2 -2
  43. package/lib/core/handler/AsOutHandler.js +2 -3
  44. package/lib/core/handler/AsRefHandler.js +2 -3
  45. package/lib/core/handler/CreateNullHandler.js +2 -3
  46. package/lib/core/handler/ExceptionHandler.js +2 -3
  47. package/lib/core/handler/GenerateLibHandler.js +2 -3
  48. package/lib/core/handler/GetAsyncOperationResultHandler.js +2 -3
  49. package/lib/core/handler/GetEnumItemHandler.js +2 -3
  50. package/lib/core/handler/GetEnumNameHandler.js +2 -2
  51. package/lib/core/handler/GetEnumValueHandler.js +2 -3
  52. package/lib/core/handler/GetInstanceMethodAsDelegateHandler.js +3 -3
  53. package/lib/core/handler/GetModuleHandler.js +2 -2
  54. package/lib/core/handler/GetRefValueHandler.js +2 -3
  55. package/lib/core/handler/GetStaticFieldHandler.js +0 -1
  56. package/lib/core/handler/GetStaticMethodAsDelegateHandler.js +3 -1
  57. package/lib/core/handler/GetTypeHandler.js +3 -3
  58. package/lib/core/handler/Handler.js +29 -29
  59. package/lib/core/handler/HeartBeatHandler.js +2 -3
  60. package/lib/core/handler/InvokeGenericMethodHandler.js +2 -4
  61. package/lib/core/handler/InvokeGenericStaticMethodHandler.js +2 -3
  62. package/lib/core/handler/InvokeStaticMethodHandler.js +1 -1
  63. package/lib/core/handler/OptimizeHandler.js +2 -3
  64. package/lib/core/handler/PluginWrapperHandler.js +2 -3
  65. package/lib/core/handler/ResolveReferenceHandler.js +1 -3
  66. package/lib/core/handler/RetrieveArrayHandler.js +2 -3
  67. package/lib/core/receiver/Receiver.js +5 -7
  68. package/lib/core/transmitter/Transmitter.js +5 -5
  69. package/lib/core/webSocketClient/WebSocketClientBrowser.js +2 -2
  70. package/lib/sdk/ActivatorDetails.js +1 -1
  71. package/lib/sdk/ConfigRuntimeFactory.js +65 -48
  72. package/lib/sdk/InvocationContext.js +10 -2
  73. package/lib/sdk/Javonet.js +31 -2
  74. package/lib/sdk/RuntimeFactory.js +49 -1
  75. package/lib/sdk/configuration/Config.js +37 -0
  76. package/lib/sdk/configuration/ConfigPriority.js +9 -0
  77. package/lib/sdk/configuration/ConfigSourceResolver.js +84 -0
  78. package/lib/sdk/configuration/ConfigsDictionary.js +118 -0
  79. package/lib/sdk/configuration/configResolvers/ConfigResolver.js +109 -0
  80. package/lib/sdk/configuration/configResolvers/ConnectionStringConfigResolver.js +119 -0
  81. package/lib/sdk/configuration/configResolvers/JsonConfigResolver.js +99 -0
  82. package/lib/sdk/configuration/configResolvers/YamlConfigResolver.js +109 -0
  83. package/lib/sdk/tools/ActivationHelper.js +1 -1
  84. package/lib/sdk/tools/JsonResolver.js +5 -1
  85. package/lib/sdk/tools/typeParsingFunctions/NetcoreTypeParsingFunctions.js +1 -1
  86. package/lib/sdk/tools/typeParsingFunctions/NodejsTypeParsingFunctions.js +1 -1
  87. package/lib/sdk/tools/typeParsingFunctions/TypeParsingUtils.js +4 -1
  88. package/lib/utils/CommandType.js +1 -1
  89. package/lib/utils/CustomError.js +1 -1
  90. package/lib/utils/Runtime.js +11 -4
  91. package/lib/utils/RuntimeLoggerBrowser.js +0 -1
  92. package/lib/utils/RuntimeNameHandler.js +37 -0
  93. package/lib/utils/TypesHandler.js +11 -5
  94. package/lib/utils/connectionData/InMemoryConnectionData.js +8 -1
  95. package/lib/utils/connectionData/WsConnectionData.js +7 -0
  96. package/lib/utils/exception/ExceptionSerializer.js +6 -2
  97. package/lib/utils/nodejs/connectionData/TcpConnectionData.js +16 -6
  98. package/lib/utils/nodejs/uuid/v4.js +0 -1
  99. package/package.json +3 -1
@@ -55,10 +55,10 @@ class AbstractHandler {
55
55
  }
56
56
  }
57
57
  /**
58
- *
59
- * @param {*} error
60
- * @param {*} class_name
61
- * @returns
58
+ *
59
+ * @param {*} error
60
+ * @param {*} class_name
61
+ * @returns
62
62
  */
63
63
  process_stack_trace(error, class_name) {
64
64
  let stackTraceArray = error.stack.split("\n").map((frame) => frame.trim());
@@ -77,10 +77,8 @@ class GetInstanceMethodAsDelegateHandler extends import_AbstractHandler.Abstract
77
77
  const methods = Object.getOwnPropertyNames(
78
78
  /** @type {{prototype: Object}} */
79
79
  type.prototype
80
- ).filter(
81
- (key) => typeof /** @type {any} */
82
- type.prototype[key] === "function"
83
- );
80
+ ).filter((key) => typeof /** @type {any} */
81
+ type.prototype[key] === "function");
84
82
  const availableMethods = methods.map((name) => `${name}()`);
85
83
  const message = `Method ${methodName} not found in class ${/** @type {{name: string}} */
86
84
  type.name}. Available instance public methods:
@@ -70,8 +70,10 @@ class GetStaticMethodAsDelegateHandler extends import_AbstractHandler.AbstractHa
70
70
  * @returns {Error} The error with detailed message.
71
71
  */
72
72
  createMethodNotFoundError(type, methodName) {
73
- const methods = Object.keys(type).filter((key) => typeof /** @type {any} */
74
- type[key] === "function");
73
+ const methods = Object.keys(type).filter(
74
+ (key) => typeof /** @type {any} */
75
+ type[key] === "function"
76
+ );
75
77
  const availableMethods = methods.map((name) => `${name}()`);
76
78
  const message = `Method ${methodName} not found in class ${/** @type {{name: string}} */
77
79
  type.name}. Available public static methods:
@@ -36,9 +36,9 @@ class GetTypeHandler extends import_AbstractHandler.AbstractHandler {
36
36
  this.loadLibaryHandler = new import_LoadLibraryHandler.LoadLibraryHandler();
37
37
  }
38
38
  /**
39
- *
40
- * @param {Command} command
41
- * @returns
39
+ *
40
+ * @param {Command} command
41
+ * @returns
42
42
  */
43
43
  process(command) {
44
44
  try {
@@ -31,7 +31,7 @@ class Transmitter {
31
31
  return import_TransmitterWrapper.TransmitterWrapper.sendCommand(messageArray);
32
32
  }
33
33
  /**
34
- * @param {string} licenseKey
34
+ * @param {string} licenseKey
35
35
  * @returns {void}
36
36
  */
37
37
  static activate(licenseKey) {
@@ -40,13 +40,13 @@ class Transmitter {
40
40
  /**
41
41
  * @param {string} configSource
42
42
  * @returns {void}
43
- */
43
+ */
44
44
  static setConfigSource(configSource) {
45
45
  return import_TransmitterWrapper.TransmitterWrapper.setConfigSource(configSource);
46
46
  }
47
47
  /**
48
- * @param {string} workingDirectory
49
- * @returns
48
+ * @param {string} workingDirectory
49
+ * @returns
50
50
  */
51
51
  static setJavonetWorkingDirectory(workingDirectory) {
52
52
  return import_TransmitterWrapper.TransmitterWrapper.setJavonetWorkingDirectory(workingDirectory);
@@ -39,6 +39,9 @@ class ConfigRuntimeFactory {
39
39
  constructor(configSource) {
40
40
  this.configSource = configSource;
41
41
  }
42
+ static _IN_MEMORY_CONNECTION_TYPES = ["inmemory", "memory"];
43
+ static _WEB_SOCKET_CONNECTION_TYPES = ["websocket", "ws"];
44
+ static _TCP_CONNECTION_TYPES = ["tcp"];
42
45
  /**
43
46
  * Creates RuntimeContext instance to interact with the .NET Framework runtime.
44
47
  * @param {string} [configName="default"] - The name of the configuration to use (optional).
@@ -118,53 +121,48 @@ class ConfigRuntimeFactory {
118
121
  */
119
122
  #getRuntimeContext(runtime, configName = "default") {
120
123
  const jsonResolver = new import_JsonResolver.JsonResolver(this.configSource);
121
- import_UtilsConst.UtilsConst.setLicenseKey(jsonResolver.getLicenseKey());
122
- if (jsonResolver.getWorkingDirectory()) {
124
+ try {
125
+ import_UtilsConst.UtilsConst.setLicenseKey(jsonResolver.getLicenseKey());
126
+ } catch (e) {
127
+ }
128
+ try {
123
129
  import_UtilsConst.UtilsConst.setJavonetWorkingDirectory(jsonResolver.getWorkingDirectory());
130
+ } catch (e) {
124
131
  }
132
+ const channelType = jsonResolver.getChannelType(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName);
133
+ const channelTypeLower = channelType ? channelType.trim().toLowerCase() : "";
134
+ let connectionData = null;
125
135
  if ((0, import_Runtime.isBrowserRuntime)()) {
126
- const channelType = jsonResolver.getChannelType(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName);
127
- let connectionData = null;
128
- if (channelType === "webSocket") {
136
+ if (ConfigRuntimeFactory._WEB_SOCKET_CONNECTION_TYPES.includes(channelTypeLower)) {
129
137
  connectionData = new import_WsConnectionData.WsConnectionData(
130
138
  jsonResolver.getChannelHost(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName)
131
139
  );
132
140
  } else {
133
- throw new Error("Unsupported connection type: " + channelType);
141
+ throw new Error("Invalid connection type. Use inmemory, tcp or websocket");
134
142
  }
135
143
  const rtmCtx = import_RuntimeContext.RuntimeContext.getInstance(runtime, connectionData);
136
144
  this.#loadModules(runtime, configName, jsonResolver, rtmCtx);
137
145
  return rtmCtx;
138
146
  }
139
147
  if ((0, import_Runtime.isNodejsRuntime)()) {
140
- try {
141
- const channelType = jsonResolver.getChannelType(
142
- import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime),
143
- configName
148
+ if (ConfigRuntimeFactory._IN_MEMORY_CONNECTION_TYPES.includes(channelTypeLower)) {
149
+ connectionData = new import_InMemoryConnectionData.InMemoryConnectionData();
150
+ } else if (ConfigRuntimeFactory._TCP_CONNECTION_TYPES.includes(channelTypeLower)) {
151
+ connectionData = new import_TcpConnectionData.TcpConnectionData(
152
+ jsonResolver.getChannelHost(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName),
153
+ /** @type {number} */
154
+ jsonResolver.getChannelPort(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName)
144
155
  );
145
- const licenseKey = jsonResolver.getLicenseKey();
146
- let connectionData = null;
147
- if (channelType === "inMemory") {
148
- connectionData = new import_InMemoryConnectionData.InMemoryConnectionData();
149
- } else if (channelType === "tcp") {
150
- connectionData = new import_TcpConnectionData.TcpConnectionData(
151
- jsonResolver.getChannelHost(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName),
152
- /** @type {number} */
153
- jsonResolver.getChannelPort(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName)
154
- );
155
- } else if (channelType === "webSocket") {
156
- connectionData = new import_WsConnectionData.WsConnectionData(
157
- jsonResolver.getChannelHost(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName)
158
- );
159
- } else {
160
- throw new Error("Unsupported connection type: " + channelType);
161
- }
162
- const rtmCtx = import_RuntimeContext.RuntimeContext.getInstance(runtime, connectionData);
163
- this.#loadModules(runtime, configName, jsonResolver, rtmCtx);
164
- return rtmCtx;
165
- } catch (error) {
166
- throw error;
156
+ } else if (ConfigRuntimeFactory._WEB_SOCKET_CONNECTION_TYPES.includes(channelTypeLower)) {
157
+ connectionData = new import_WsConnectionData.WsConnectionData(
158
+ jsonResolver.getChannelHost(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName)
159
+ );
160
+ } else {
161
+ throw new Error("Invalid connection type. Use inmemory, tcp or websocket");
167
162
  }
163
+ const rtmCtx = import_RuntimeContext.RuntimeContext.getInstance(runtime, connectionData);
164
+ this.#loadModules(runtime, configName, jsonResolver, rtmCtx);
165
+ return rtmCtx;
168
166
  }
169
167
  throw new Error("Unsupported runtime environment");
170
168
  }
@@ -176,22 +174,27 @@ class ConfigRuntimeFactory {
176
174
  */
177
175
  #loadModules(runtime, configName, jsonResolver, rtmCtx) {
178
176
  try {
179
- const modules = jsonResolver.getModules(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName).split(",").filter((module2) => module2.trim() !== "");
180
- if ((0, import_Runtime.isNodejsRuntime)()) {
181
- const path = (
182
- /** @type {import('path').PlatformPath} */
183
- /** @type {unknown} */
184
- requireDynamic("path")
185
- );
186
- const configDirectoryAbsolutePath = process.cwd();
187
- modules.forEach((module2) => {
188
- if (path.isAbsolute(module2)) {
189
- rtmCtx.loadLibrary(module2);
190
- } else {
191
- rtmCtx.loadLibrary(path.join(configDirectoryAbsolutePath, module2));
192
- }
193
- });
177
+ const modules = jsonResolver.getModules(import_RuntimeNameHandler.RuntimeNameHandler.getName(runtime), configName).split(",").map((m) => m.trim()).filter((m) => m !== "");
178
+ if (!(0, import_Runtime.isNodejsRuntime)()) {
179
+ return;
180
+ }
181
+ const path = (
182
+ /** @type {import('path').PlatformPath} */
183
+ /** @type {unknown} */
184
+ requireDynamic("path")
185
+ );
186
+ let configDirectoryAbsolutePath = process.cwd();
187
+ const isCfgSourcePath = jsonResolver.isConfigSourcePath;
188
+ if (isCfgSourcePath) {
189
+ configDirectoryAbsolutePath = path.dirname(jsonResolver.configSource);
194
190
  }
191
+ modules.forEach((module2) => {
192
+ if (path.isAbsolute(module2)) {
193
+ rtmCtx.loadLibrary(module2);
194
+ } else {
195
+ rtmCtx.loadLibrary(path.join(configDirectoryAbsolutePath, module2));
196
+ }
197
+ });
195
198
  } catch (error) {
196
199
  throw error;
197
200
  }
@@ -381,7 +381,11 @@ class InvocationContext {
381
381
  */
382
382
  getResultType() {
383
383
  const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
384
- const invocationContext = new InvocationContext(this.#runtimeName, this.#connectionData, this.#buildCommand(localCommand));
384
+ const invocationContext = new InvocationContext(
385
+ this.#runtimeName,
386
+ this.#connectionData,
387
+ this.#buildCommand(localCommand)
388
+ );
385
389
  const result = invocationContext.execute().getValue();
386
390
  return (
387
391
  /** @type {string} */
@@ -551,7 +555,11 @@ class InvocationWsContext extends InvocationContext {
551
555
  // @ts-expect-error
552
556
  async getResultType() {
553
557
  const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
554
- const invocationContext = new InvocationWsContext(this.#runtimeName, this.#connectionData, this.#buildCommand(localCommand));
558
+ const invocationContext = new InvocationWsContext(
559
+ this.#runtimeName,
560
+ this.#connectionData,
561
+ this.#buildCommand(localCommand)
562
+ );
555
563
  const result = await invocationContext.execute();
556
564
  return (
557
565
  /** @type {string} */
@@ -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");
@@ -35,6 +37,8 @@ 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
39
  var import_UtilsConst = require("../utils/UtilsConst.cjs");
40
+ var import_ConfigSourceResolver = require("./configuration/ConfigSourceResolver.cjs");
41
+ var import_ConfigPriority = require("./configuration/ConfigPriority.cjs");
38
42
  const import_meta = {};
39
43
  const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
40
44
  let _Transmitter = null;
@@ -119,11 +123,29 @@ class Javonet {
119
123
  static setJavonetWorkingDirectory(path) {
120
124
  import_UtilsConst.UtilsConst.setJavonetWorkingDirectory(path);
121
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
+ }
122
143
  }
123
144
  // Annotate the CommonJS export names for ESM import in node:
124
145
  0 && (module.exports = {
125
146
  CommandDeserializer,
126
147
  CommandSerializer,
148
+ ConfigPriority,
127
149
  Javonet,
128
150
  TcpConnectionData,
129
151
  WsConnectionData
@@ -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
+ });