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
@@ -12,7 +12,7 @@ import { RuntimeContext } from './RuntimeContext.js'
12
12
  */
13
13
  export class RuntimeFactory {
14
14
  /**
15
- * @param {IConnectionData} connectionData
15
+ * @param {IConnectionData} connectionData
16
16
  */
17
17
  constructor(connectionData) {
18
18
  this.connectionData = connectionData
@@ -81,6 +81,15 @@ export class RuntimeFactory {
81
81
  return RuntimeContext.getInstance(RuntimeName.Nodejs, this.connectionData)
82
82
  }
83
83
 
84
+ /**
85
+ * Creates RuntimeContext instance to interact with the PHP runtime.
86
+ * @return {RuntimeContext} a RuntimeContext instance for the PHP runtime
87
+ * @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
88
+ */
89
+ php() {
90
+ return RuntimeContext.getInstance(RuntimeName.Php, this.connectionData)
91
+ }
92
+
84
93
  /**
85
94
  * Creates RuntimeContext instance to interact with the Python runtime.
86
95
  * @return {RuntimeContext} a RuntimeContext instance for the Python runtime
@@ -89,4 +98,43 @@ export class RuntimeFactory {
89
98
  python27() {
90
99
  return RuntimeContext.getInstance(RuntimeName.Python27, this.connectionData)
91
100
  }
101
+
102
+ /**
103
+ * @param {{ runtime: import("../types.js").RuntimeName; connectionData: import("../utils/connectionData/IConnectionData.js").IConnectionData; modules: any; }} config
104
+ */
105
+ static initializeRuntimeContext(config) {
106
+ const rtmCtx = RuntimeContext.getInstance(config.runtime, config.connectionData)
107
+
108
+ const modules = (config.modules || '')
109
+ .split(',')
110
+ .map((/** @type {string} */ m) => m.trim())
111
+ .filter((/** @type {string} */ m) => m !== '')
112
+
113
+ // try to get Node's path module; if unavailable, fall back to simple checks
114
+ let pathModule = null
115
+ try {
116
+ // eslint-disable-next-line no-eval
117
+ const _require = typeof require !== 'undefined' ? require : eval('require')
118
+ pathModule = _require('path')
119
+ } catch (e) {
120
+ pathModule = null
121
+ }
122
+
123
+ modules.forEach((/** @type {string} */ module) => {
124
+ const isAbsolute = pathModule
125
+ ? pathModule.isAbsolute(module)
126
+ : module.startsWith('/') || /^[A-Za-z]:\\/.test(module)
127
+
128
+ if (isAbsolute) {
129
+ rtmCtx.loadLibrary(module)
130
+ } else {
131
+ const resolved = pathModule
132
+ ? pathModule.join(process.cwd(), module)
133
+ : `${process.cwd()}/${module}`
134
+ rtmCtx.loadLibrary(resolved)
135
+ }
136
+ })
137
+
138
+ return rtmCtx
139
+ }
92
140
  }
@@ -0,0 +1,37 @@
1
+ // @ts-check
2
+
3
+ class Config {
4
+ /**
5
+ * @param {*} runtime
6
+ * @param {*} connectionData
7
+ * @param {string} [plugins=""]
8
+ * @param {string} [modules=""]
9
+ */
10
+ constructor(runtime, connectionData, plugins = '', modules = '') {
11
+ this.runtime = runtime
12
+ this.connectionData = connectionData
13
+ this.plugins = plugins ?? ''
14
+ this.modules = modules ?? ''
15
+ }
16
+
17
+ toString() {
18
+ const parts = []
19
+ parts.push(`Runtime: ${this.runtime}`)
20
+
21
+ if (this.connectionData != null) {
22
+ parts.push(`Host: ${this.connectionData}`)
23
+ }
24
+
25
+ if (String(this.plugins).trim()) {
26
+ parts.push(`Plugins: ${this.plugins}`)
27
+ }
28
+
29
+ if (String(this.modules).trim()) {
30
+ parts.push(`Modules: ${this.modules}`)
31
+ }
32
+
33
+ return parts.join(', ')
34
+ }
35
+ }
36
+
37
+ export { Config }
@@ -0,0 +1,9 @@
1
+ // @ts-check
2
+ export const ConfigPriority = /** @type {const} */ ({
3
+ RuntimeSpecificEnv: 1,
4
+ GlobalEnv: 2,
5
+ RuntimeSpecificFile: 3,
6
+ GlobalFile: 4,
7
+ User: 5,
8
+ DefaultLibrary: 6,
9
+ })
@@ -0,0 +1,84 @@
1
+ // lib/sdk/configuration/ConfigSourceResolver.js
2
+ // lib/sdk/configuration/ConfigSourceResolver.js
3
+ import fs from 'fs'
4
+ import process from 'process'
5
+
6
+ import { ConfigsDictionary } from './ConfigsDictionary.js'
7
+ import { JsonConfigResolver } from './configResolvers/JsonConfigResolver.js'
8
+ import { YamlConfigResolver } from './configResolvers/YamlConfigResolver.js'
9
+ import { ConnectionStringConfigResolver } from './configResolvers/ConnectionStringConfigResolver.js'
10
+
11
+ class ConfigSourceResolver {
12
+ static addConfigs(priority, configSource) {
13
+ console.log(`Adding config from source: ${configSource} with priority '${priority}'`)
14
+ const configString = ConfigSourceResolver._getConfigSourceAsString(configSource)
15
+ ConfigSourceResolver._parseConfigsAndAddToCollection(priority, configString)
16
+ }
17
+
18
+ static getConfig(configName) {
19
+ console.log(`Retrieving config ${configName}`)
20
+ return ConfigsDictionary.getConfig(configName)
21
+ }
22
+
23
+ static clearConfigs() {
24
+ ConfigsDictionary.clearConfigs()
25
+ }
26
+
27
+ static _getConfigSourceAsString(configSource) {
28
+ if (!configSource || configSource.trim() === '') {
29
+ throw new Error('Config source cannot be null or whitespace.')
30
+ }
31
+
32
+ const envValue = process.env[configSource]
33
+ if (envValue && envValue.trim() !== '') {
34
+ configSource = envValue
35
+ }
36
+
37
+ if (fs.existsSync(configSource) && fs.statSync(configSource).isFile()) {
38
+ configSource = fs.readFileSync(configSource, { encoding: 'utf-8' })
39
+ }
40
+
41
+ return configSource.trim()
42
+ }
43
+
44
+ static _parseConfigsAndAddToCollection(priority, configString) {
45
+ // JSON
46
+ try {
47
+ const jsonObject = JSON.parse(configString)
48
+ JsonConfigResolver.addConfigs(priority, jsonObject)
49
+ return
50
+ } catch (ex) {
51
+ if (ex instanceof SyntaxError) {
52
+ // not JSON
53
+ } else {
54
+ console.log('Failed to parse config source as JSON: ' + ex)
55
+ }
56
+ }
57
+
58
+ // YAML
59
+ try {
60
+ YamlConfigResolver.addConfigs(priority, configString)
61
+ return
62
+ } catch (ex) {
63
+ if (ex.name === 'SyntaxError') {
64
+ // not YAML
65
+ } else {
66
+ console.log('Failed to parse config source as YAML: ' + ex)
67
+ }
68
+ }
69
+
70
+ // Connection string
71
+ try {
72
+ ConnectionStringConfigResolver.addConfigs(priority, configString)
73
+ return
74
+ } catch (ex) {
75
+ console.log('Failed to parse config source as connection string: ' + ex)
76
+ }
77
+
78
+ throw new Error(
79
+ 'Config source is not valid JSON, YAML, or connection string format:\n' + configString
80
+ )
81
+ }
82
+ }
83
+
84
+ export { ConfigSourceResolver }
@@ -0,0 +1,118 @@
1
+ // @ts-check
2
+
3
+ class ConfigsDictionary {
4
+ /** @type {Map<string, Map<number, any>>} */
5
+ static _configurations_collection = new Map()
6
+
7
+ /**
8
+ * Normalize priority to a numeric value.
9
+ * Accepts either a number or an object with a numeric `value` property.
10
+ * @param {any} priority
11
+ * @returns {number|undefined}
12
+ */
13
+ static _normalizePriority(priority) {
14
+ if (typeof priority === 'number' && Number.isFinite(priority)) {
15
+ return priority
16
+ }
17
+ if (
18
+ priority &&
19
+ typeof priority === 'object' &&
20
+ 'value' in priority &&
21
+ typeof priority.value === 'number'
22
+ ) {
23
+ return priority.value
24
+ }
25
+ return undefined
26
+ }
27
+
28
+ /**
29
+ * Add a configuration for a given name and priority.
30
+ * If the same name+priority already exists, it will not be overwritten.
31
+ * @param {string} name
32
+ * @param {number|{value:number}} priority
33
+ * @param {*} config
34
+ */
35
+ static addConfig(name, priority, config) {
36
+ if (!name || String(name).trim() === '') {
37
+ console.log('Config name cannot be null or whitespace. Skipping add.')
38
+ return
39
+ }
40
+ if (config == null) {
41
+ console.log('Config instance is null. Skipping add.')
42
+ return
43
+ }
44
+
45
+ const key = ConfigsDictionary._normalizePriority(priority)
46
+ if (typeof key !== 'number') {
47
+ console.log(
48
+ 'Priority must be a numeric value or an object with a numeric `value` property. Skipping add.'
49
+ )
50
+ return
51
+ }
52
+
53
+ let perPriority = ConfigsDictionary._configurations_collection.get(name)
54
+ if (!perPriority) {
55
+ perPriority = new Map()
56
+ ConfigsDictionary._configurations_collection.set(name, perPriority)
57
+ }
58
+
59
+ if (perPriority.has(key)) {
60
+ console.log(
61
+ `Config with name \`${name}\` and priority \`${key}\` already exists. It will not be added or updated.`
62
+ )
63
+ return
64
+ }
65
+
66
+ perPriority.set(key, config)
67
+
68
+ let serialized
69
+ try {
70
+ serialized = JSON.stringify(config)
71
+ } catch {
72
+ serialized = String(config)
73
+ }
74
+
75
+ console.log(`Added configuration \`${name}\` with priority \`${key}\` and parameters ${serialized}`)
76
+ }
77
+
78
+ /**
79
+ * Retrieve the configuration with the numerically smallest priority for the given name.
80
+ * Throws if name is invalid or no configuration is found.
81
+ * @param {string} name
82
+ * @returns {*}
83
+ */
84
+ static getConfig(name) {
85
+ if (!name || String(name).trim() === '') {
86
+ throw new Error('Config name cannot be null or whitespace')
87
+ }
88
+
89
+ const perPriority = ConfigsDictionary._configurations_collection.get(name)
90
+ if (!perPriority || perPriority.size === 0) {
91
+ throw new Error(`Configuration ${name} not found`)
92
+ }
93
+
94
+ // keys are numeric priorities; pick the smallest numeric key
95
+ const keysArray = [...perPriority.keys()]
96
+ const smallest = keysArray.reduce((min, k) => (k < min ? k : min), keysArray[0])
97
+ const config = perPriority.get(smallest)
98
+
99
+ let serialized
100
+ try {
101
+ serialized = JSON.stringify(config)
102
+ } catch {
103
+ serialized = String(config)
104
+ }
105
+
106
+ console.log(
107
+ `Retrieved configuration \`${name}\` with priority \`${smallest}\` and parameters ${serialized}`
108
+ )
109
+ return config
110
+ }
111
+
112
+ /** Clear all stored configurations. */
113
+ static clearConfigs() {
114
+ ConfigsDictionary._configurations_collection.clear()
115
+ }
116
+ }
117
+
118
+ export { ConfigsDictionary }
@@ -0,0 +1,109 @@
1
+ // @ts-check
2
+
3
+ import { RuntimeNameHandler } from '../../../utils/RuntimeNameHandler.js'
4
+ import { InMemoryConnectionData } from '../../../utils/connectionData/InMemoryConnectionData.js'
5
+ import { WsConnectionData } from '../../../utils/connectionData/WsConnectionData.js'
6
+ import { TcpConnectionData } from '../../../utils/nodejs/connectionData/TcpConnectionData.js'
7
+
8
+ class ConfigResolver {
9
+ /**
10
+ * Parse a runtime string into the runtime enum/name using RuntimeNameHandler.
11
+ * @param {string} runtime
12
+ * @returns {*}
13
+ */
14
+ static tryParseRuntime(runtime) {
15
+ if (!runtime || String(runtime).trim() === '') {
16
+ throw new Error('Runtime string cannot be null or whitespace.')
17
+ }
18
+ const normalized = String(runtime).trim().toLowerCase()
19
+ return RuntimeNameHandler.getRuntime(normalized)
20
+ }
21
+
22
+ /**
23
+ * Build appropriate connection data object from a host string.
24
+ * - empty / null => InMemoryConnectionData
25
+ * - "inmemory" or "in-memory" => InMemoryConnectionData
26
+ * - ws:// or wss:// => WsConnectionData(fullAddress)
27
+ * - tcp://... => parsed by parseTcp
28
+ * - host:port or host:port/... => TcpConnectionData(host, port) if valid, otherwise InMemoryConnectionData
29
+ * @param {string} hostValue
30
+ * @returns {InMemoryConnectionData|WsConnectionData|TcpConnectionData}
31
+ */
32
+ static buildConnectionData(hostValue) {
33
+ if (!hostValue || String(hostValue).trim() === '') {
34
+ return new InMemoryConnectionData()
35
+ }
36
+
37
+ const hv = String(hostValue).trim()
38
+ const lower = hv.toLowerCase()
39
+
40
+ if (lower === 'inmemory' || lower === 'in-memory') {
41
+ return new InMemoryConnectionData()
42
+ }
43
+
44
+ if (lower.startsWith('ws://') || lower.startsWith('wss://')) {
45
+ return new WsConnectionData(hv)
46
+ }
47
+
48
+ if (lower.startsWith('tcp://')) {
49
+ try {
50
+ // slice off 'tcp://'
51
+ return ConfigResolver.parseTcp(hv.slice(6))
52
+ } catch (e) {
53
+ return new InMemoryConnectionData()
54
+ }
55
+ }
56
+
57
+ const colon = hv.indexOf(':')
58
+ if (colon > 0 && colon < hv.length - 1) {
59
+ let portPart = hv.substring(colon + 1)
60
+ const slash = portPart.indexOf('/')
61
+ if (slash >= 0) {
62
+ portPart = portPart.substring(0, slash)
63
+ }
64
+ try {
65
+ const port = parseInt(portPart, 10)
66
+ if (!Number.isFinite(port) || Number.isNaN(port)) {
67
+ throw new Error('invalid port')
68
+ }
69
+ const hostOnly = hv.substring(0, colon)
70
+ if (String(hostOnly).trim()) {
71
+ try {
72
+ return new TcpConnectionData(hostOnly, port)
73
+ } catch (e) {
74
+ return new InMemoryConnectionData()
75
+ }
76
+ }
77
+ } catch (e) {
78
+ // fall through to in-memory
79
+ }
80
+ }
81
+
82
+ return new InMemoryConnectionData()
83
+ }
84
+
85
+ /**
86
+ * Parse tcp address portion (after tcp://) into TcpConnectionData.
87
+ * Expected formats: host:port or host:port/...
88
+ * Throws Error on invalid format or port.
89
+ * @param {string} address
90
+ * @returns {TcpConnectionData}
91
+ */
92
+ static parseTcp(address) {
93
+ const slash = address.indexOf('/')
94
+ const hostPort = slash >= 0 ? address.substring(0, slash) : address
95
+ const colon = hostPort.lastIndexOf(':')
96
+ if (colon <= 0 || colon >= hostPort.length - 1) {
97
+ throw new Error('Invalid tcp:// format.')
98
+ }
99
+ const host = hostPort.substring(0, colon)
100
+ const portStr = hostPort.substring(colon + 1)
101
+ const port = parseInt(portStr, 10)
102
+ if (!Number.isFinite(port) || Number.isNaN(port)) {
103
+ throw new Error('Invalid port in tcp:// address.')
104
+ }
105
+ return new TcpConnectionData(host, port)
106
+ }
107
+ }
108
+
109
+ export { ConfigResolver }
@@ -0,0 +1,119 @@
1
+ // @ts-check
2
+
3
+ import { Config } from '../Config.js'
4
+ import { ConfigsDictionary } from '../ConfigsDictionary.js'
5
+ import { ActivationHelper } from '../../tools/ActivationHelper.js'
6
+ import { ConfigResolver } from './ConfigResolver.js'
7
+
8
+ class ConnectionStringConfigResolver extends ConfigResolver {
9
+ /**
10
+ * Parse and add multiple configuration lines from a connection string source.
11
+ * @param {any} priority
12
+ * @param {string} connectionStringSource
13
+ */
14
+ static addConfigs(priority, connectionStringSource) {
15
+ if (!connectionStringSource || String(connectionStringSource).trim() === '') {
16
+ throw new Error('Connection string source cannot be null or empty.')
17
+ }
18
+
19
+ const normalized = String(connectionStringSource).replace(/\r\n/g, '\n').replace(/\r/g, '\n')
20
+
21
+ const lines = normalized
22
+ .split('\n')
23
+ .map((l) => l.trim())
24
+ .filter((l) => l.length > 0)
25
+
26
+ for (const line of lines) {
27
+ if (line.startsWith('#') || line.startsWith('//')) {
28
+ continue
29
+ }
30
+ if (line.toLowerCase().startsWith('licensekey')) {
31
+ ConnectionStringConfigResolver._setLicenseKey(line)
32
+ continue
33
+ }
34
+
35
+ try {
36
+ const keyValues = ConnectionStringConfigResolver._parseKeyValues(line)
37
+ const configName = keyValues.name
38
+ const runtimeValue = keyValues.runtime
39
+
40
+ if (!configName || String(configName).trim() === '') {
41
+ throw new Error('Missing or empty config name.')
42
+ }
43
+ if (!runtimeValue || String(runtimeValue).trim() === '') {
44
+ throw new Error('Missing or empty runtime.')
45
+ }
46
+
47
+ const runtimeName = ConfigResolver.tryParseRuntime(runtimeValue)
48
+ const hostValue = keyValues.host
49
+ const connectionData = ConfigResolver.buildConnectionData(hostValue)
50
+ const plugins = keyValues.plugins || ''
51
+ const modules = keyValues.modules || ''
52
+
53
+ const config = new Config(runtimeName, connectionData, plugins, modules)
54
+ ConfigsDictionary.addConfig(configName, priority, config)
55
+ } catch (ex) {
56
+ console.log(`Failed to parse config line: '${line}'. Reason: ${ex}`)
57
+ throw ex
58
+ }
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Extract and set temporary license key from a line like "licensekey=VALUE;..."
64
+ * @param {string} line
65
+ * @private
66
+ */
67
+ static _setLicenseKey(line) {
68
+ const eq = line.indexOf('=')
69
+ if (eq > 0 && eq < line.length - 1) {
70
+ let valuePortion = line.substring(eq + 1).trim()
71
+ const semicolon = valuePortion.indexOf(';')
72
+ if (semicolon >= 0) {
73
+ valuePortion = valuePortion.substring(0, semicolon).trim()
74
+ }
75
+ const hashIdx = valuePortion.indexOf('#')
76
+ if (hashIdx >= 0) {
77
+ valuePortion = valuePortion.substring(0, hashIdx).trim()
78
+ }
79
+ const slashes = valuePortion.indexOf('//')
80
+ if (slashes >= 0) {
81
+ valuePortion = valuePortion.substring(0, slashes).trim()
82
+ }
83
+ ActivationHelper.setTemporaryLicenseKey(valuePortion)
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Parse semicolon-separated key=value tokens into an object.
89
+ * Ignores malformed tokens and logs them.
90
+ * @param {string} line
91
+ * @returns {Record<string, string>}
92
+ * @private
93
+ */
94
+ static _parseKeyValues(line) {
95
+ /** @type {Record<string, string>} */
96
+ const result = {}
97
+ const segments = line
98
+ .split(';')
99
+ .map((s) => s.trim())
100
+ .filter((s) => s.length > 0)
101
+
102
+ for (const segment of segments) {
103
+ const eq = segment.indexOf('=')
104
+ if (eq <= 0 || eq === segment.length - 1) {
105
+ console.log(`Ignoring malformed token '${segment}' in line: ${line}`)
106
+ continue
107
+ }
108
+ const key = segment.substring(0, eq).trim().toLowerCase()
109
+ const value = segment.substring(eq + 1).trim()
110
+ if (key) {
111
+ result[key] = value
112
+ }
113
+ }
114
+
115
+ return result
116
+ }
117
+ }
118
+
119
+ export { ConnectionStringConfigResolver }
@@ -0,0 +1,99 @@
1
+ // @ts-check
2
+
3
+ import { Config } from '../Config.js'
4
+ import { ConfigsDictionary } from '../ConfigsDictionary.js'
5
+ import { ConfigResolver } from './ConfigResolver.js'
6
+ import { ActivationHelper } from '../../tools/ActivationHelper.js'
7
+
8
+ class JsonConfigResolver extends ConfigResolver {
9
+ /**
10
+ * Parse and add configurations from a JSON object.
11
+ * @param {any} priority
12
+ * @param {Record<string, unknown>} jsonObject
13
+ */
14
+ static addConfigs(priority, jsonObject) {
15
+ if (jsonObject == null) {
16
+ throw new Error('json_object cannot be None')
17
+ }
18
+ if (typeof jsonObject !== 'object' || Array.isArray(jsonObject)) {
19
+ throw new Error('Root JSON element must be a dict/object.')
20
+ }
21
+
22
+ const licenseKey = /** @type {Record<string, unknown>} */ (jsonObject).licenseKey
23
+ if (typeof licenseKey === 'string') {
24
+ ActivationHelper.setTemporaryLicenseKey(licenseKey.trim())
25
+ }
26
+
27
+ const configs = /** @type {Record<string, unknown>} */ (jsonObject).configurations
28
+ if (typeof configs !== 'object' || configs == null || Array.isArray(configs)) {
29
+ throw new Error("JSON must contain 'configurations' object.")
30
+ }
31
+
32
+ for (const [configName, cfg] of Object.entries(/** @type {Record<string, unknown>} */ (configs))) {
33
+ try {
34
+ if (typeof cfg !== 'object' || cfg == null || Array.isArray(cfg)) {
35
+ throw new Error('Configuration value must be an object/dict.')
36
+ }
37
+
38
+ const runtimeValue = JsonConfigResolver._getRequiredString(
39
+ /** @type {Record<string, unknown>} */ (cfg),
40
+ 'runtime'
41
+ )
42
+ const runtimeName = ConfigResolver.tryParseRuntime(runtimeValue)
43
+
44
+ const host = JsonConfigResolver._getOptionalString(
45
+ /** @type {Record<string, unknown>} */ (cfg),
46
+ 'host'
47
+ )
48
+ const connectionData = ConfigResolver.buildConnectionData(host)
49
+
50
+ const plugins = JsonConfigResolver._getOptionalString(
51
+ /** @type {Record<string, unknown>} */ (cfg),
52
+ 'plugins'
53
+ )
54
+ const modules = JsonConfigResolver._getOptionalString(
55
+ /** @type {Record<string, unknown>} */ (cfg),
56
+ 'modules'
57
+ )
58
+
59
+ const config = new Config(runtimeName, connectionData, plugins, modules)
60
+ ConfigsDictionary.addConfig(configName, priority, config)
61
+ } catch (ex) {
62
+ console.log(`Failed to add config '${configName}': ${ex}`)
63
+ }
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Get a required string property from an object, trimmed.
69
+ * Throws if missing or empty.
70
+ * @param {Record<string, unknown>} obj
71
+ * @param {string} property
72
+ * @returns {string}
73
+ * @private
74
+ */
75
+ static _getRequiredString(obj, property) {
76
+ const value = obj[property]
77
+ if (typeof value !== 'string' || value.trim() === '') {
78
+ throw new Error(`Missing or invalid '${property}' property.`)
79
+ }
80
+ return value.trim()
81
+ }
82
+
83
+ /**
84
+ * Get an optional string property; return empty string when missing or not a string.
85
+ * @param {Record<string, unknown>} obj
86
+ * @param {string} property
87
+ * @returns {string}
88
+ * @private
89
+ */
90
+ static _getOptionalString(obj, property) {
91
+ const value = obj[property]
92
+ if (typeof value === 'string') {
93
+ return value
94
+ }
95
+ return ''
96
+ }
97
+ }
98
+
99
+ export { JsonConfigResolver }