javonet-nodejs-sdk 2.5.16 → 2.5.18

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 (204) hide show
  1. package/dist/core/delegatesCache/DelegatesCache.cjs +1 -5
  2. package/dist/core/handler/AbstractHandler.cjs +24 -9
  3. package/dist/core/handler/ArrayGetItemHandler.cjs +5 -4
  4. package/dist/core/handler/ArrayGetRankHandler.cjs +4 -3
  5. package/dist/core/handler/ArrayGetSizeHandler.cjs +4 -3
  6. package/dist/core/handler/ArrayHandler.cjs +3 -0
  7. package/dist/core/handler/ArraySetItemHandler.cjs +5 -4
  8. package/dist/core/handler/CastingHandler.cjs +3 -1
  9. package/dist/core/handler/ConvertTypeHandler.cjs +4 -4
  10. package/dist/core/handler/CreateClassInstanceHandler.cjs +6 -5
  11. package/dist/core/handler/DestructReferenceHandler.cjs +3 -0
  12. package/dist/core/handler/EnableNamespaceHandler.cjs +3 -0
  13. package/dist/core/handler/EnableTypeHandler.cjs +4 -3
  14. package/dist/core/handler/GetGlobalStaticFieldHandler.cjs +4 -3
  15. package/dist/core/handler/GetInstanceFieldHandler.cjs +4 -3
  16. package/dist/core/handler/GetInstanceMethodAsDelegateHandler.cjs +15 -4
  17. package/dist/core/handler/GetStaticFieldHandler.cjs +5 -3
  18. package/dist/core/handler/GetStaticMethodAsDelegateHandler.cjs +10 -10
  19. package/dist/core/handler/GetTypeHandler.cjs +10 -2
  20. package/dist/core/handler/Handler.cjs +8 -11
  21. package/dist/core/handler/InvokeGlobalFunctionHandler.cjs +4 -3
  22. package/dist/core/handler/InvokeInstanceMethodHandler.cjs +4 -3
  23. package/dist/core/handler/InvokeStaticMethodHandler.cjs +4 -3
  24. package/dist/core/handler/LoadLibraryHandler.cjs +11 -10
  25. package/dist/core/handler/PassDelegateHandler.cjs +2 -4
  26. package/dist/core/handler/SetGlobalStaticFieldHandler.cjs +4 -3
  27. package/dist/core/handler/SetInstanceFieldHandler.cjs +4 -3
  28. package/dist/core/handler/SetStaticFieldHandler.cjs +4 -3
  29. package/dist/core/handler/ValueHandler.cjs +4 -0
  30. package/dist/core/interpreter/Interpreter.cjs +29 -17
  31. package/dist/core/namespaceCache/NamespaceCache.cjs +19 -10
  32. package/dist/core/protocol/CommandDeserializer.cjs +10 -2
  33. package/dist/core/protocol/CommandSerializer.cjs +24 -4
  34. package/dist/core/protocol/TypeDeserializer.cjs +35 -0
  35. package/dist/core/protocol/TypeSerializer.cjs +51 -7
  36. package/dist/core/receiver/Receiver.cjs +3 -5
  37. package/dist/core/receiver/ReceiverNative.cjs +6 -0
  38. package/dist/core/transmitter/Transmitter.cjs +19 -5
  39. package/dist/core/transmitter/TransmitterWebsocket.cjs +8 -5
  40. package/dist/core/transmitter/TransmitterWebsocketBrowser.cjs +1 -1
  41. package/dist/core/transmitter/TransmitterWrapper.cjs +25 -8
  42. package/dist/core/typeCache/TypeCache.cjs +15 -10
  43. package/dist/core/webSocketClient/WebSocketClient.cjs +22 -12
  44. package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +2 -2
  45. package/dist/sdk/ConfigRuntimeFactory.cjs +92 -98
  46. package/dist/sdk/InvocationContext.cjs +229 -203
  47. package/dist/sdk/Javonet.cjs +14 -33
  48. package/dist/sdk/RuntimeContext.cjs +138 -99
  49. package/dist/sdk/RuntimeFactory.cjs +3 -0
  50. package/dist/sdk/tools/ActivationHelper.cjs +66 -0
  51. package/dist/sdk/tools/JsonResolver.cjs +214 -0
  52. package/dist/types/core/handler/AbstractHandler.d.ts +23 -4
  53. package/dist/types/core/handler/ArrayGetItemHandler.d.ts +8 -1
  54. package/dist/types/core/handler/ArrayGetRankHandler.d.ts +8 -1
  55. package/dist/types/core/handler/ArrayGetSizeHandler.d.ts +8 -1
  56. package/dist/types/core/handler/ArrayHandler.d.ts +8 -1
  57. package/dist/types/core/handler/ArraySetItemHandler.d.ts +8 -1
  58. package/dist/types/core/handler/CastingHandler.d.ts +4 -0
  59. package/dist/types/core/handler/ConvertTypeHandler.d.ts +8 -4
  60. package/dist/types/core/handler/CreateClassInstanceHandler.d.ts +8 -1
  61. package/dist/types/core/handler/DestructReferenceHandler.d.ts +8 -1
  62. package/dist/types/core/handler/EnableNamespaceHandler.d.ts +8 -1
  63. package/dist/types/core/handler/EnableTypeHandler.d.ts +8 -1
  64. package/dist/types/core/handler/GetGlobalStaticFieldHandler.d.ts +8 -1
  65. package/dist/types/core/handler/GetInstanceFieldHandler.d.ts +8 -1
  66. package/dist/types/core/handler/GetStaticFieldHandler.d.ts +9 -1
  67. package/dist/types/core/handler/GetStaticMethodAsDelegateHandler.d.ts +4 -3
  68. package/dist/types/core/handler/GetTypeHandler.d.ts +17 -8
  69. package/dist/types/core/handler/Handler.d.ts +8 -8
  70. package/dist/types/core/handler/InvokeDelegateHandler.d.ts +4 -0
  71. package/dist/types/core/handler/InvokeGlobalFunctionHandler.d.ts +8 -1
  72. package/dist/types/core/handler/InvokeInstanceMethodHandler.d.ts +8 -1
  73. package/dist/types/core/handler/InvokeStaticMethodHandler.d.ts +8 -1
  74. package/dist/types/core/handler/LoadLibraryHandler.d.ts +8 -3
  75. package/dist/types/core/handler/SetGlobalStaticFieldHandler.d.ts +4 -0
  76. package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +8 -1
  77. package/dist/types/core/handler/SetStaticFieldHandler.d.ts +8 -1
  78. package/dist/types/core/handler/ValueHandler.d.ts +9 -1
  79. package/dist/types/core/interpreter/Interpreter.d.ts +11 -10
  80. package/dist/types/core/namespaceCache/NamespaceCache.d.ts +17 -5
  81. package/dist/types/core/protocol/CommandDeserializer.d.ts +10 -3
  82. package/dist/types/core/protocol/CommandSerializer.d.ts +19 -2
  83. package/dist/types/core/protocol/TypeDeserializer.d.ts +46 -11
  84. package/dist/types/core/protocol/TypeSerializer.d.ts +53 -13
  85. package/dist/types/core/receiver/Receiver.d.ts +2 -2
  86. package/dist/types/core/receiver/ReceiverNative.d.ts +8 -2
  87. package/dist/types/core/transmitter/Transmitter.d.ts +20 -4
  88. package/dist/types/core/transmitter/TransmitterWebsocket.d.ts +8 -4
  89. package/dist/types/core/transmitter/TransmitterWebsocketBrowser.d.ts +4 -7
  90. package/dist/types/core/transmitter/TransmitterWrapper.d.ts +12 -3
  91. package/dist/types/core/typeCache/TypeCache.d.ts +15 -5
  92. package/dist/types/core/webSocketClient/WebSocketClient.d.ts +17 -21
  93. package/dist/types/sdk/ConfigRuntimeFactory.d.ts +9 -6
  94. package/dist/types/sdk/InvocationContext.d.ts +38 -6
  95. package/dist/types/sdk/Javonet.d.ts +12 -7
  96. package/dist/types/sdk/RuntimeContext.d.ts +23 -7
  97. package/dist/types/sdk/RuntimeFactory.d.ts +9 -2
  98. package/dist/types/sdk/tools/ActivationHelper.d.ts +20 -0
  99. package/dist/types/sdk/tools/JsonResolver.d.ts +87 -0
  100. package/dist/types/utils/Command.d.ts +18 -14
  101. package/dist/types/utils/CreateRequire.browser.d.ts +1 -0
  102. package/dist/types/utils/CreateRequire.node.d.ts +2 -0
  103. package/dist/types/utils/CustomError.d.ts +5 -1
  104. package/dist/types/utils/Runtime.d.ts +2 -3
  105. package/dist/types/utils/RuntimeNameHandler.d.ts +6 -2
  106. package/dist/types/utils/Type.d.ts +1 -0
  107. package/dist/types/utils/TypesHandler.d.ts +16 -0
  108. package/dist/types/utils/UtilsConst.d.ts +32 -0
  109. package/dist/types/utils/connectionData/IConnectionData.d.ts +16 -3
  110. package/dist/types/utils/connectionData/InMemoryConnectionData.d.ts +4 -3
  111. package/dist/types/utils/connectionData/WsConnectionData.d.ts +7 -10
  112. package/dist/types/utils/nodejs/connectionData/TcpConnectionData.d.ts +17 -10
  113. package/dist/utils/Command.cjs +9 -9
  114. package/dist/utils/CreateRequire.browser.cjs +30 -0
  115. package/dist/utils/CreateRequire.node.cjs +28 -0
  116. package/dist/utils/CustomError.cjs +4 -0
  117. package/dist/utils/Runtime.cjs +24 -18
  118. package/dist/utils/RuntimeLogger.cjs +2 -4
  119. package/dist/utils/RuntimeLoggerBrowser.cjs +1 -3
  120. package/dist/utils/RuntimeNameHandler.cjs +1 -1
  121. package/dist/utils/Type.cjs +2 -1
  122. package/dist/utils/TypesHandler.cjs +55 -0
  123. package/dist/utils/UtilsConst.cjs +101 -0
  124. package/dist/utils/connectionData/IConnectionData.cjs +9 -0
  125. package/dist/utils/connectionData/InMemoryConnectionData.cjs +10 -0
  126. package/dist/utils/connectionData/WsConnectionData.cjs +4 -0
  127. package/dist/utils/nodejs/connectionData/TcpConnectionData.cjs +45 -25
  128. package/lib/core/delegatesCache/DelegatesCache.js +1 -0
  129. package/lib/core/handler/AbstractHandler.js +27 -9
  130. package/lib/core/handler/ArrayGetItemHandler.js +9 -1
  131. package/lib/core/handler/ArrayGetRankHandler.js +9 -0
  132. package/lib/core/handler/ArrayGetSizeHandler.js +8 -0
  133. package/lib/core/handler/ArrayHandler.js +8 -0
  134. package/lib/core/handler/ArraySetItemHandler.js +11 -1
  135. package/lib/core/handler/CastingHandler.js +8 -1
  136. package/lib/core/handler/ConvertTypeHandler.js +9 -4
  137. package/lib/core/handler/CreateClassInstanceHandler.js +10 -4
  138. package/lib/core/handler/DestructReferenceHandler.js +8 -0
  139. package/lib/core/handler/EnableNamespaceHandler.js +8 -0
  140. package/lib/core/handler/EnableTypeHandler.js +8 -0
  141. package/lib/core/handler/GetGlobalStaticFieldHandler.js +9 -0
  142. package/lib/core/handler/GetInstanceFieldHandler.js +8 -0
  143. package/lib/core/handler/GetInstanceMethodAsDelegateHandler.js +9 -4
  144. package/lib/core/handler/GetStaticFieldHandler.js +9 -0
  145. package/lib/core/handler/GetStaticMethodAsDelegateHandler.js +8 -7
  146. package/lib/core/handler/GetTypeHandler.js +15 -5
  147. package/lib/core/handler/Handler.js +13 -18
  148. package/lib/core/handler/InvokeDelegateHandler.js +5 -0
  149. package/lib/core/handler/InvokeGlobalFunctionHandler.js +11 -1
  150. package/lib/core/handler/InvokeInstanceMethodHandler.js +8 -0
  151. package/lib/core/handler/InvokeStaticMethodHandler.js +8 -0
  152. package/lib/core/handler/LoadLibraryHandler.js +11 -0
  153. package/lib/core/handler/SetGlobalStaticFieldHandler.js +10 -0
  154. package/lib/core/handler/SetInstanceFieldHandler.js +7 -0
  155. package/lib/core/handler/SetStaticFieldHandler.js +8 -0
  156. package/lib/core/handler/ValueHandler.js +9 -0
  157. package/lib/core/interpreter/Interpreter.js +42 -24
  158. package/lib/core/namespaceCache/NamespaceCache.js +14 -0
  159. package/lib/core/protocol/CommandDeserializer.js +11 -2
  160. package/lib/core/protocol/CommandSerializer.js +40 -9
  161. package/lib/core/protocol/TypeDeserializer.js +36 -0
  162. package/lib/core/protocol/TypeSerializer.js +62 -7
  163. package/lib/core/receiver/Receiver.js +3 -2
  164. package/lib/core/receiver/ReceiverNative.js +8 -0
  165. package/lib/core/transmitter/Transmitter.js +18 -1
  166. package/lib/core/transmitter/TransmitterWebsocket.js +12 -5
  167. package/lib/core/transmitter/TransmitterWebsocketBrowser.js +2 -4
  168. package/lib/core/transmitter/TransmitterWrapper.js +27 -6
  169. package/lib/core/typeCache/TypeCache.js +9 -0
  170. package/lib/core/webSocketClient/WebSocketClient.js +33 -30
  171. package/lib/core/webSocketClient/WebSocketClientBrowser.js +5 -6
  172. package/lib/sdk/ConfigRuntimeFactory.js +70 -68
  173. package/lib/sdk/InvocationContext.js +94 -26
  174. package/lib/sdk/Javonet.js +18 -36
  175. package/lib/sdk/RuntimeContext.js +109 -29
  176. package/lib/sdk/RuntimeFactory.js +7 -0
  177. package/lib/sdk/tools/ActivationHelper.js +51 -0
  178. package/lib/sdk/tools/JsonResolver.js +226 -0
  179. package/lib/types.d.ts +57 -0
  180. package/lib/utils/Command.js +14 -9
  181. package/lib/utils/CreateRequire.browser.js +5 -0
  182. package/lib/utils/CreateRequire.node.js +3 -0
  183. package/lib/utils/CustomError.js +5 -0
  184. package/lib/utils/Runtime.js +25 -6
  185. package/lib/utils/RuntimeLogger.js +3 -0
  186. package/lib/utils/RuntimeNameHandler.js +6 -1
  187. package/lib/utils/Type.js +2 -1
  188. package/lib/utils/TypesHandler.js +35 -0
  189. package/lib/utils/UtilsConst.js +88 -0
  190. package/lib/utils/connectionData/IConnectionData.js +14 -0
  191. package/lib/utils/connectionData/InMemoryConnectionData.js +15 -0
  192. package/lib/utils/connectionData/WsConnectionData.js +9 -0
  193. package/lib/utils/nodejs/connectionData/TcpConnectionData.js +35 -5
  194. package/package.json +13 -3
  195. package/dist/sdk/tools/browser/ConfigSourceResolver.cjs +0 -153
  196. package/dist/sdk/tools/nodejs/JsonFileResolver.cjs +0 -120
  197. package/dist/types/sdk/tools/browser/ConfigSourceResolver.d.ts +0 -46
  198. package/dist/types/sdk/tools/nodejs/JsonFileResolver.d.ts +0 -13
  199. package/dist/types/utils/nodejs/TypesConverter.d.ts +0 -48
  200. package/dist/utils/nodejs/TypesConverter.cjs +0 -102
  201. package/lib/declarations.d.ts +0 -35
  202. package/lib/sdk/tools/browser/ConfigSourceResolver.js +0 -146
  203. package/lib/sdk/tools/nodejs/JsonFileResolver.js +0 -106
  204. package/lib/utils/nodejs/TypesConverter.js +0 -91
@@ -0,0 +1,51 @@
1
+ // @ts-check
2
+ import { isBrowserRuntime } from '../../utils/Runtime.js'
3
+
4
+ class ActivationHelper {
5
+ /** @type {string} */
6
+ static temporaryLicenseKey = 'License key not set'
7
+
8
+ /**
9
+ * @param {string} value
10
+ */
11
+ static setTemporaryLicenseKey(value) {
12
+ if (!value || value === 'your-license-key') {
13
+ return
14
+ }
15
+ // TODO: Uncomment this when we have a way to send messages to App Insights
16
+ // if (ActivationHelper.temporaryLicenseKey !== value) {
17
+ // SdkMessageHelper.sendExceptionToAppInsights('SdkMessage', 'Activation');
18
+ // }
19
+ ActivationHelper.temporaryLicenseKey = value
20
+ }
21
+
22
+ /**
23
+ * @returns {string}
24
+ */
25
+ static getTemporaryLicenseKey() {
26
+ return ActivationHelper.temporaryLicenseKey
27
+ }
28
+
29
+ /**
30
+ * @returns {Promise<string>}
31
+ */
32
+ static async getLicenseKey() {
33
+ try {
34
+ return ActivationHelper._getLicenseKeyFromFile()
35
+ } catch {
36
+ return ActivationHelper.temporaryLicenseKey
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @returns {string}
42
+ */
43
+ static _getLicenseKeyFromFile() {
44
+ if (!isBrowserRuntime()) {
45
+ throw new Error('ActivationHelper is not supported in the browser runtime.')
46
+ }
47
+ return ""
48
+ }
49
+ }
50
+
51
+ export { ActivationHelper }
@@ -0,0 +1,226 @@
1
+ //@ts-check
2
+ import { isNodejsRuntime, getRequire } from '../../utils/Runtime.js'
3
+
4
+ /**
5
+ * @typedef {import('../../types.d.ts').RuntimeChannelType} RuntimeChannelType
6
+ * @typedef {import('../../types.d.ts').ConfigSource} ConfigSource
7
+ * @typedef {import('../../types.d.ts').RuntimeChannel} RuntimeChannel
8
+ * @typedef {import('../../types.d.ts').Runtime} Runtime
9
+ * @typedef {import('../../types.d.ts').Runtimes} Runtimes
10
+ * @typedef {import('../../types.d.ts').RuntimeType} RuntimeType
11
+ */
12
+
13
+ /**
14
+ * @param {any} param
15
+ * @returns {boolean}
16
+ */
17
+ function isValidObject(param) {
18
+ return typeof param === 'object' && param !== null && !Array.isArray(param)
19
+ }
20
+
21
+ /**
22
+ * @param {string | ConfigSource} param
23
+ * @returns {boolean}
24
+ */
25
+ function isValidJson(param) {
26
+ try {
27
+ if (typeof param === 'string') {
28
+ const parsed = JSON.parse(param)
29
+ return typeof parsed === 'object' && parsed !== null
30
+ }
31
+ return false
32
+ } catch (e) {
33
+ return false
34
+ }
35
+ }
36
+
37
+ const requireDynamic = getRequire(import.meta.url)
38
+
39
+ /** @type {any | null} */
40
+ let fs = null
41
+
42
+ class JsonResolver {
43
+ /** @type {ConfigSource} */
44
+ jsonObject
45
+ /** @type {string | ConfigSource} */
46
+ configSource
47
+
48
+ /**
49
+ * @param {string | ConfigSource} configSource
50
+ */
51
+ constructor(configSource) {
52
+ this.configSource = JSON.stringify(configSource)
53
+ this.jsonObject = this._getJsonObject(configSource)
54
+ }
55
+
56
+ /**
57
+ * @returns {Partial<Runtimes>}
58
+ */
59
+ get runtimes() {
60
+ return this.jsonObject?.runtimes || {}
61
+ }
62
+
63
+ /**
64
+ * @returns {string}
65
+ */
66
+ get licenseKey() {
67
+ return this.jsonObject?.licenseKey || 'your-license-key'
68
+ }
69
+
70
+ /**
71
+ * @returns {string}
72
+ */
73
+ get workingDirectory() {
74
+ return this.jsonObject?.workingDirectory || ''
75
+ }
76
+
77
+ /**
78
+ * @returns {string}
79
+ */
80
+ getLicenseKey() {
81
+ if (!this.licenseKey) {
82
+ throw new Error('License key not found in configuration source. Check your configuration source.')
83
+ }
84
+ return this.licenseKey
85
+ }
86
+
87
+ /**
88
+ * @returns {string}
89
+ */
90
+ getWorkingDirectory() {
91
+ return this.workingDirectory
92
+ }
93
+
94
+ /**
95
+ * @param {RuntimeType} runtimeName
96
+ * @param {string} configName
97
+ * @returns {RuntimeChannelType}
98
+ */
99
+ getChannelType(runtimeName, configName) {
100
+ const channel = this._getChannel(runtimeName, configName)
101
+ return channel.type
102
+ }
103
+
104
+ /**
105
+ * @param {RuntimeType} runtimeName
106
+ * @param {string} configName
107
+ * @returns {string}
108
+ */
109
+ getChannelHost(runtimeName, configName) {
110
+ const channel = this._getChannel(runtimeName, configName)
111
+ if (channel.host === undefined) {
112
+ throw new Error(`Host not found for channel in runtime ${runtimeName}, config ${configName}`)
113
+ }
114
+ return channel.host
115
+ }
116
+
117
+ /**
118
+ * @param {RuntimeType} runtimeName
119
+ * @param {string} configName
120
+ * @returns {number|string}
121
+ */
122
+ getChannelPort(runtimeName, configName) {
123
+ const channel = this._getChannel(runtimeName, configName)
124
+ if (channel.port === undefined) {
125
+ throw new Error(`Port not found for channel in runtime ${runtimeName}, config ${configName}`)
126
+ }
127
+ return channel.port
128
+ }
129
+
130
+ /**
131
+ * @param {RuntimeType} runtimeName
132
+ * @param {string} configName
133
+ * @returns {string}
134
+ */
135
+ getModules(runtimeName, configName) {
136
+ const runtime = this._getRuntime(runtimeName, configName)
137
+ return runtime.modules || ''
138
+ }
139
+
140
+ /**
141
+ * @private
142
+ * @param {string | ConfigSource} configSource
143
+ * @returns {ConfigSource}
144
+ */
145
+ _getJsonObject(configSource) {
146
+ if (isValidObject(configSource)) {
147
+ return /** @type {ConfigSource} */ (configSource)
148
+ }
149
+ if (typeof configSource === 'string' && isValidJson(configSource)) {
150
+ const parsedJson = JSON.parse(configSource)
151
+ if (isValidObject(parsedJson)) {
152
+ return parsedJson
153
+ }
154
+ }
155
+ if (isNodejsRuntime()) {
156
+ if (!fs) {
157
+ fs = requireDynamic('fs')
158
+ }
159
+ if (fs?.existsSync(configSource)) {
160
+ const jsonText = fs.readFileSync(configSource, 'utf8')
161
+ if (isValidJson(jsonText)) {
162
+ const parsedFromFile = JSON.parse(jsonText)
163
+ if (isValidObject(parsedFromFile)) {
164
+ return parsedFromFile
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+ throw new Error(
171
+ `Configuration source is not valid. Check your configuration:${String(this.configSource)}`
172
+ )
173
+ }
174
+
175
+ /**
176
+ * @private
177
+ * @param {RuntimeType} runtimeName
178
+ * @param {string} configName
179
+ * @returns {Runtime}
180
+ */
181
+ _getRuntime(runtimeName, configName) {
182
+ const runtimeList = this.runtimes[runtimeName]
183
+
184
+ if (Array.isArray(runtimeList)) {
185
+ const runtime = runtimeList.find((item) => item.name === configName)
186
+ if (runtime) {
187
+ return runtime
188
+ }
189
+ } else if (typeof runtimeList?.name === 'string' && runtimeList?.name === configName) {
190
+ return runtimeList
191
+ }
192
+
193
+ throw new Error(
194
+ `Runtime config '${configName}' not found in configuration source for runtime '${runtimeName}'. Check your configuration source.`
195
+ )
196
+ }
197
+
198
+ /**
199
+ * @private
200
+ * @param {RuntimeType} runtimeName
201
+ * @param {string} configName
202
+ * @returns {string}
203
+ */
204
+ _getRuntimeName(runtimeName, configName) {
205
+ const runtime = this._getRuntime(runtimeName, configName)
206
+ return runtime.name
207
+ }
208
+
209
+ /**
210
+ * @private
211
+ * @param {RuntimeType} runtimeName
212
+ * @param {string} configName
213
+ * @returns {RuntimeChannel}
214
+ */
215
+ _getChannel(runtimeName, configName) {
216
+ const runtime = this._getRuntime(runtimeName, configName)
217
+ if (!runtime.channel) {
218
+ throw new Error(
219
+ `Channel not found for runtime config '${configName}' and runtime '${runtimeName}'. Check your configuration source.`
220
+ )
221
+ }
222
+ return runtime.channel
223
+ }
224
+ }
225
+
226
+ export { JsonResolver }
package/lib/types.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ export interface ConnectionData {
2
+ readonly connectionType: ConnectionType
3
+ readonly hostname: string
4
+ serializeConnectionData(): string
5
+ }
6
+
7
+ export enum RuntimeName {
8
+ Clr = 0,
9
+ Go = 1,
10
+ Jvm = 2,
11
+ Netcore = 3,
12
+ Perl = 4,
13
+ Python = 5,
14
+ Ruby = 6,
15
+ Nodejs = 7,
16
+ Cpp = 8,
17
+ Php = 9,
18
+ Python27 = 10,
19
+ }
20
+
21
+ export type RuntimeType =
22
+ | 'clr'
23
+ | 'go'
24
+ | 'jvm'
25
+ | 'netcore'
26
+ | 'perl'
27
+ | 'python'
28
+ | 'ruby'
29
+ | 'nodejs'
30
+ | 'cpp'
31
+ | 'php'
32
+ | 'python27'
33
+ export type RuntimeChannelType = 'inMemory' | 'tcp' | 'webSocket'
34
+
35
+ export interface RuntimeChannel {
36
+ type: RuntimeChannelType
37
+ host?: string
38
+ port?: number
39
+ }
40
+
41
+ export interface Runtime {
42
+ name: string
43
+ customOptions: string
44
+ modules: string
45
+ channel: RuntimeChannel
46
+ runtimeName: RuntimeName
47
+ }
48
+
49
+ export type Runtimes = {
50
+ [Key in keyof typeof RuntimeType]: Runtime[] | Runtime
51
+ }
52
+
53
+ export interface ConfigSource {
54
+ [key: string]: any
55
+ licenseKey: string
56
+ runtimes: Partial<Runtimes>
57
+ }
@@ -1,9 +1,14 @@
1
+ // @ts-check
1
2
  import { CommandType } from './CommandType.js'
2
3
 
4
+ /**
5
+ * @typedef {import('../types.d.ts').RuntimeName} RuntimeName
6
+ */
7
+
3
8
  export class Command {
4
9
  /**
5
10
  * Constructs a new Command instance.
6
- * @param {number} runtimeName - The runtime name associated with the command.
11
+ * @param {RuntimeName} runtimeName - The runtime name associated with the command.
7
12
  * @param {number} commandType - The type of the command.
8
13
  * @param {any} [payload] - The optional payload of the command.
9
14
  * @method
@@ -15,27 +20,27 @@ export class Command {
15
20
  }
16
21
 
17
22
  /**
18
- * @param {any} [response]
19
- * @param {number} runtimeName
23
+ * @param {unknown} response
24
+ * @param {RuntimeName} runtimeName
25
+ * @returns {Command}
20
26
  */
21
27
  static createResponse(response, runtimeName) {
22
28
  return new Command(runtimeName, CommandType.Value, [response])
23
29
  }
24
30
 
25
31
  /**
26
- * @param {any} [response]
27
- * @param {number} runtimeName
28
- * @method
32
+ * @param {unknown} response
33
+ * @param {RuntimeName} runtimeName
34
+ * @returns {Command}
29
35
  */
30
36
  static createReference(response, runtimeName) {
31
37
  return new Command(runtimeName, CommandType.Reference, [response])
32
38
  }
33
39
 
34
40
  /**
35
- * @param {any} [response]
36
- * @param {number} runtimeName
41
+ * @param {unknown} response
42
+ * @param {RuntimeName} runtimeName
37
43
  * @returns {Command}
38
- * @method
39
44
  */
40
45
  static createArrayResponse(response, runtimeName) {
41
46
  return new Command(runtimeName, CommandType.Array, response)
@@ -0,0 +1,5 @@
1
+ const createRequire = () => {
2
+ return new Error('createRequire is not supported in the browser')
3
+ }
4
+
5
+ export { createRequire }
@@ -0,0 +1,3 @@
1
+ import { createRequire } from 'module'
2
+
3
+ export { createRequire }
@@ -1,4 +1,9 @@
1
+ // @ts-check
1
2
  export class CustomError extends Error {
3
+ /**
4
+ * @param {string} message
5
+ * @param {string} cause
6
+ */
2
7
  constructor(message, cause) {
3
8
  super(`${message}: ${cause}`)
4
9
  this.name = 'CustomError'
@@ -1,6 +1,11 @@
1
- import { createRequire } from 'module'
2
- import path from 'path'
3
- import { fileURLToPath, pathToFileURL } from 'url'
1
+ import { createRequire } from './CreateRequire.node.js'
2
+
3
+ /** @type {import('url').pathToFileURL | null} */
4
+ let pathToFileURL = null
5
+ /** @type {import('url').fileURLToPath | null} */
6
+ let fileURLToPath = null
7
+ /** @type {import('path').path | null} */
8
+ let path = null
4
9
 
5
10
  /**
6
11
  * Validate if the runtime is Node.js
@@ -37,7 +42,7 @@ export function getRuntimeExtension() {
37
42
  /**
38
43
  * Get the require function
39
44
  * @param {string} callerPath - The path to the caller
40
- * @returns {import('module').createRequire}
45
+ * @returns {any}
41
46
  */
42
47
  export const getRequire = (callerPath) => {
43
48
  try {
@@ -45,11 +50,9 @@ export const getRequire = (callerPath) => {
45
50
  if (typeof require !== 'undefined') {
46
51
  return require
47
52
  }
48
-
49
53
  if (callerPath === undefined) {
50
54
  return createRequire(import.meta.url)
51
55
  }
52
-
53
56
  const baseUrl = callerPath?.startsWith('file:') ? callerPath : pathToFileURL(callerPath).href
54
57
  return createRequire(baseUrl)
55
58
  }
@@ -60,6 +63,9 @@ export const getRequire = (callerPath) => {
60
63
  }
61
64
 
62
65
  export const getDirname = () => {
66
+ if (isBrowserRuntime()) {
67
+ return new Error('Runtime not supported')
68
+ }
63
69
  // when esm runtime, __dirname is undefined
64
70
  if (isEsmRuntime()) {
65
71
  const __filename = fileURLToPath(import.meta.url)
@@ -92,3 +98,16 @@ export const getDependency = (dependencyName, callerPathOrUrl) => {
92
98
  )
93
99
  }
94
100
  }
101
+
102
+ if (isNodejsRuntime()) {
103
+ const requireDynamic = getRequire(import.meta.url)
104
+ if (fileURLToPath === null) {
105
+ fileURLToPath = requireDynamic('url').fileURLToPath
106
+ }
107
+ if (path === null) {
108
+ path = requireDynamic('path')
109
+ }
110
+ if (pathToFileURL === null) {
111
+ pathToFileURL = requireDynamic('url').pathToFileURL
112
+ }
113
+ }
@@ -1,6 +1,9 @@
1
+ // @ts-check
1
2
  import { getRequire, isNodejsRuntime } from './Runtime.js'
2
3
 
4
+ /** @type {any | null} */
3
5
  let os = null
6
+ /** @type {any | null} */
4
7
  let process = null
5
8
 
6
9
  const requireDynamic = getRequire(import.meta.url)
@@ -1,9 +1,14 @@
1
+ // @ts-check
1
2
  import { RuntimeName } from './RuntimeName.js'
2
3
 
4
+ /**
5
+ * @typedef {import('../types.d.ts').RuntimeType} RuntimeType
6
+ */
7
+
3
8
  class RuntimeNameHandler {
4
9
  /**
5
10
  * @param {number} runtimeName
6
- * @returns {string}
11
+ * @returns {RuntimeType}
7
12
  */
8
13
  static getName(runtimeName) {
9
14
  switch (runtimeName) {
package/lib/utils/Type.js CHANGED
@@ -12,4 +12,5 @@ export const Type = /** @type {const} */ ({
12
12
  JAVONET_UNSIGNED_LONG_LONG: 9,
13
13
  JAVONET_UNSIGNED_INTEGER: 10,
14
14
  JAVONET_NULL: 11,
15
- })
15
+ JAVONET_VOID: 12,
16
+ })
@@ -0,0 +1,35 @@
1
+ // @ts-check
2
+ /**
3
+ * TypesHandler class provides utilities for converting between types.
4
+ */
5
+ class TypesHandler {
6
+ /**
7
+ * Converts a JavaScript type to a JType equivalent.
8
+ * @param {Function} type - The JavaScript type.
9
+ * @returns {string} The corresponding type name
10
+ */
11
+ static convertTypeToJType(type) {
12
+ switch (type) {
13
+ case Boolean:
14
+ return "JType.Boolean"
15
+ case Number:
16
+ return "JType.Float"
17
+ case String:
18
+ return "JType.String"
19
+ case Object:
20
+ return typeof type
21
+ default:
22
+ return typeof type
23
+ }
24
+ }
25
+
26
+ /**
27
+ * @param {unknown} value
28
+ * @returns {boolean}
29
+ */
30
+ static isPrimitiveOrNullOrUndefined(value) {
31
+ return value === null || value === undefined || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'
32
+ }
33
+ }
34
+
35
+ export {TypesHandler}
@@ -0,0 +1,88 @@
1
+ // @ts-check
2
+ import { getRequire, isNodejsRuntime } from './Runtime.js'
3
+
4
+ /** @type {any | null} */
5
+ let fs = null
6
+ /** @type {any | null} */
7
+ let path = null
8
+
9
+ const requireDynamic = getRequire(import.meta.url)
10
+
11
+ class UtilsConst {
12
+ /** @type {string} */
13
+ static _javonetWorkingDirectory = '.'
14
+ /** @type {string} */
15
+ static _configSource = ''
16
+ /** @type {string} */
17
+ static _licenseKey = ''
18
+
19
+ /**
20
+ * @param {string} inputPath
21
+ */
22
+ static setJavonetWorkingDirectory(inputPath) {
23
+ if (!inputPath) {
24
+ return
25
+ }
26
+ let normalizedPath = inputPath.replace(/\\/g, '/')
27
+
28
+ if (!normalizedPath.endsWith('/')) {
29
+ normalizedPath += '/'
30
+ }
31
+ if (isNodejsRuntime()) {
32
+ if (!fs) {
33
+ fs = requireDynamic('fs')
34
+ }
35
+ if (!fs.existsSync(normalizedPath)) {
36
+ fs.mkdirSync(normalizedPath, { recursive: true })
37
+ fs.chmodSync(normalizedPath, 0o700)
38
+ }
39
+ }
40
+ UtilsConst._javonetWorkingDirectory = normalizedPath
41
+ }
42
+
43
+ /**
44
+ * @returns {string}
45
+ */
46
+ static getJavonetWorkingDirectory() {
47
+ if (isNodejsRuntime() && !UtilsConst._javonetWorkingDirectory) {
48
+ if (!path) {
49
+ path = requireDynamic('path')
50
+ }
51
+ UtilsConst._javonetWorkingDirectory = path.resolve() + '/'
52
+ }
53
+ return UtilsConst._javonetWorkingDirectory
54
+ }
55
+
56
+ /**
57
+ * @param {string} value
58
+ */
59
+ static setConfigSource(value) {
60
+ UtilsConst._configSource = value
61
+ }
62
+
63
+ /**
64
+ * @returns {string}
65
+ */
66
+ static getConfigSource() {
67
+ return UtilsConst._configSource
68
+ }
69
+
70
+ /**
71
+ * @param {string} value
72
+ */
73
+ static setLicenseKey(value) {
74
+ if (!value || value === 'your-license-key') {
75
+ return
76
+ }
77
+ UtilsConst._licenseKey = value
78
+ }
79
+
80
+ /**
81
+ * @returns {string}
82
+ */
83
+ static getLicenseKey() {
84
+ return UtilsConst._licenseKey
85
+ }
86
+ }
87
+
88
+ export { UtilsConst }
@@ -1,12 +1,26 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @typedef {import('../ConnectionType.js').ConnectionType} ConnectionType
5
+ */
1
6
  export class IConnectionData {
7
+ /**
8
+ * @returns {ConnectionType}
9
+ */
2
10
  get connectionType() {
3
11
  throw new Error('You have to implement the method connectionType!')
4
12
  }
5
13
 
14
+ /**
15
+ * @returns {string}
16
+ */
6
17
  get hostname() {
7
18
  throw new Error('You have to implement the method hostname!')
8
19
  }
9
20
 
21
+ /**
22
+ * @returns {number[]}
23
+ */
10
24
  serializeConnectionData() {
11
25
  throw new Error('You have to implement the method serializeConnectionData!')
12
26
  }
@@ -1,6 +1,11 @@
1
+ // @ts-check
1
2
  import { ConnectionType } from '../ConnectionType.js'
2
3
  import { IConnectionData } from './IConnectionData.js'
3
4
 
5
+ /**
6
+ * @typedef {import('../ConnectionType.js').ConnectionType} ConnectionType
7
+ */
8
+
4
9
  /**
5
10
  * @extends IConnectionData
6
11
  */
@@ -11,14 +16,24 @@ class InMemoryConnectionData extends IConnectionData {
11
16
  this._hostname = ''
12
17
  }
13
18
 
19
+ /**
20
+ * @returns {ConnectionType}
21
+ */
14
22
  get connectionType() {
15
23
  return this._connectionType
16
24
  }
17
25
 
26
+ /**
27
+ * @returns {string}
28
+ */
18
29
  get hostname() {
19
30
  return this._hostname
20
31
  }
21
32
 
33
+ /**
34
+ * Serializes the connection data.
35
+ * @returns {number[]} An array of connection data values.
36
+ */
22
37
  serializeConnectionData() {
23
38
  return [this.connectionType, 0, 0, 0, 0, 0, 0]
24
39
  }