javonet-nodejs-sdk 2.5.17 → 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 (193) hide show
  1. package/dist/core/handler/AbstractHandler.cjs +23 -6
  2. package/dist/core/handler/ArrayGetItemHandler.cjs +4 -1
  3. package/dist/core/handler/ArrayGetRankHandler.cjs +3 -0
  4. package/dist/core/handler/ArrayGetSizeHandler.cjs +3 -0
  5. package/dist/core/handler/ArrayHandler.cjs +3 -0
  6. package/dist/core/handler/ArraySetItemHandler.cjs +4 -1
  7. package/dist/core/handler/CastingHandler.cjs +3 -1
  8. package/dist/core/handler/ConvertTypeHandler.cjs +4 -4
  9. package/dist/core/handler/CreateClassInstanceHandler.cjs +5 -2
  10. package/dist/core/handler/DestructReferenceHandler.cjs +3 -0
  11. package/dist/core/handler/EnableNamespaceHandler.cjs +3 -0
  12. package/dist/core/handler/EnableTypeHandler.cjs +3 -0
  13. package/dist/core/handler/GetGlobalStaticFieldHandler.cjs +3 -0
  14. package/dist/core/handler/GetInstanceFieldHandler.cjs +3 -0
  15. package/dist/core/handler/GetInstanceMethodAsDelegateHandler.cjs +15 -4
  16. package/dist/core/handler/GetStaticFieldHandler.cjs +4 -0
  17. package/dist/core/handler/GetStaticMethodAsDelegateHandler.cjs +8 -6
  18. package/dist/core/handler/GetTypeHandler.cjs +10 -2
  19. package/dist/core/handler/Handler.cjs +8 -11
  20. package/dist/core/handler/InvokeGlobalFunctionHandler.cjs +3 -0
  21. package/dist/core/handler/InvokeInstanceMethodHandler.cjs +3 -0
  22. package/dist/core/handler/InvokeStaticMethodHandler.cjs +3 -0
  23. package/dist/core/handler/LoadLibraryHandler.cjs +4 -0
  24. package/dist/core/handler/SetGlobalStaticFieldHandler.cjs +3 -0
  25. package/dist/core/handler/SetInstanceFieldHandler.cjs +3 -0
  26. package/dist/core/handler/SetStaticFieldHandler.cjs +3 -0
  27. package/dist/core/handler/ValueHandler.cjs +4 -0
  28. package/dist/core/interpreter/Interpreter.cjs +28 -12
  29. package/dist/core/namespaceCache/NamespaceCache.cjs +12 -0
  30. package/dist/core/protocol/CommandDeserializer.cjs +10 -2
  31. package/dist/core/protocol/CommandSerializer.cjs +24 -4
  32. package/dist/core/protocol/TypeDeserializer.cjs +35 -0
  33. package/dist/core/protocol/TypeSerializer.cjs +51 -7
  34. package/dist/core/receiver/Receiver.cjs +1 -1
  35. package/dist/core/receiver/ReceiverNative.cjs +6 -0
  36. package/dist/core/transmitter/Transmitter.cjs +18 -2
  37. package/dist/core/transmitter/TransmitterWebsocket.cjs +8 -5
  38. package/dist/core/transmitter/TransmitterWebsocketBrowser.cjs +1 -1
  39. package/dist/core/transmitter/TransmitterWrapper.cjs +25 -8
  40. package/dist/core/typeCache/TypeCache.cjs +8 -0
  41. package/dist/core/webSocketClient/WebSocketClient.cjs +22 -12
  42. package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +2 -2
  43. package/dist/sdk/ConfigRuntimeFactory.cjs +60 -55
  44. package/dist/sdk/InvocationContext.cjs +81 -23
  45. package/dist/sdk/Javonet.cjs +14 -33
  46. package/dist/sdk/RuntimeContext.cjs +85 -30
  47. package/dist/sdk/RuntimeFactory.cjs +3 -0
  48. package/dist/sdk/tools/ActivationHelper.cjs +66 -0
  49. package/dist/sdk/tools/JsonResolver.cjs +214 -0
  50. package/dist/types/core/handler/AbstractHandler.d.ts +23 -4
  51. package/dist/types/core/handler/ArrayGetItemHandler.d.ts +8 -1
  52. package/dist/types/core/handler/ArrayGetRankHandler.d.ts +8 -1
  53. package/dist/types/core/handler/ArrayGetSizeHandler.d.ts +8 -1
  54. package/dist/types/core/handler/ArrayHandler.d.ts +8 -1
  55. package/dist/types/core/handler/ArraySetItemHandler.d.ts +8 -1
  56. package/dist/types/core/handler/CastingHandler.d.ts +4 -0
  57. package/dist/types/core/handler/ConvertTypeHandler.d.ts +8 -4
  58. package/dist/types/core/handler/CreateClassInstanceHandler.d.ts +8 -1
  59. package/dist/types/core/handler/DestructReferenceHandler.d.ts +8 -1
  60. package/dist/types/core/handler/EnableNamespaceHandler.d.ts +8 -1
  61. package/dist/types/core/handler/EnableTypeHandler.d.ts +8 -1
  62. package/dist/types/core/handler/GetGlobalStaticFieldHandler.d.ts +8 -1
  63. package/dist/types/core/handler/GetInstanceFieldHandler.d.ts +8 -1
  64. package/dist/types/core/handler/GetStaticFieldHandler.d.ts +9 -1
  65. package/dist/types/core/handler/GetStaticMethodAsDelegateHandler.d.ts +4 -3
  66. package/dist/types/core/handler/GetTypeHandler.d.ts +17 -8
  67. package/dist/types/core/handler/Handler.d.ts +8 -8
  68. package/dist/types/core/handler/InvokeDelegateHandler.d.ts +4 -0
  69. package/dist/types/core/handler/InvokeGlobalFunctionHandler.d.ts +8 -1
  70. package/dist/types/core/handler/InvokeInstanceMethodHandler.d.ts +8 -1
  71. package/dist/types/core/handler/InvokeStaticMethodHandler.d.ts +8 -1
  72. package/dist/types/core/handler/LoadLibraryHandler.d.ts +8 -3
  73. package/dist/types/core/handler/SetGlobalStaticFieldHandler.d.ts +4 -0
  74. package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +8 -1
  75. package/dist/types/core/handler/SetStaticFieldHandler.d.ts +8 -1
  76. package/dist/types/core/handler/ValueHandler.d.ts +9 -1
  77. package/dist/types/core/interpreter/Interpreter.d.ts +11 -10
  78. package/dist/types/core/namespaceCache/NamespaceCache.d.ts +17 -5
  79. package/dist/types/core/protocol/CommandDeserializer.d.ts +10 -3
  80. package/dist/types/core/protocol/CommandSerializer.d.ts +19 -2
  81. package/dist/types/core/protocol/TypeDeserializer.d.ts +46 -11
  82. package/dist/types/core/protocol/TypeSerializer.d.ts +53 -13
  83. package/dist/types/core/receiver/Receiver.d.ts +2 -2
  84. package/dist/types/core/receiver/ReceiverNative.d.ts +8 -2
  85. package/dist/types/core/transmitter/Transmitter.d.ts +20 -4
  86. package/dist/types/core/transmitter/TransmitterWebsocket.d.ts +8 -4
  87. package/dist/types/core/transmitter/TransmitterWebsocketBrowser.d.ts +4 -7
  88. package/dist/types/core/transmitter/TransmitterWrapper.d.ts +12 -3
  89. package/dist/types/core/typeCache/TypeCache.d.ts +15 -5
  90. package/dist/types/core/webSocketClient/WebSocketClient.d.ts +17 -21
  91. package/dist/types/sdk/ConfigRuntimeFactory.d.ts +9 -6
  92. package/dist/types/sdk/InvocationContext.d.ts +38 -6
  93. package/dist/types/sdk/Javonet.d.ts +12 -7
  94. package/dist/types/sdk/RuntimeContext.d.ts +23 -7
  95. package/dist/types/sdk/RuntimeFactory.d.ts +9 -2
  96. package/dist/types/sdk/tools/ActivationHelper.d.ts +20 -0
  97. package/dist/types/sdk/tools/JsonResolver.d.ts +87 -0
  98. package/dist/types/utils/Command.d.ts +18 -14
  99. package/dist/types/utils/CustomError.d.ts +5 -1
  100. package/dist/types/utils/Runtime.d.ts +1 -2
  101. package/dist/types/utils/RuntimeNameHandler.d.ts +6 -2
  102. package/dist/types/utils/Type.d.ts +1 -0
  103. package/dist/types/utils/TypesHandler.d.ts +16 -0
  104. package/dist/types/utils/UtilsConst.d.ts +32 -0
  105. package/dist/types/utils/connectionData/IConnectionData.d.ts +16 -3
  106. package/dist/types/utils/connectionData/InMemoryConnectionData.d.ts +4 -3
  107. package/dist/types/utils/connectionData/WsConnectionData.d.ts +7 -10
  108. package/dist/types/utils/nodejs/connectionData/TcpConnectionData.d.ts +17 -10
  109. package/dist/utils/Command.cjs +9 -9
  110. package/dist/utils/CustomError.cjs +4 -0
  111. package/dist/utils/RuntimeNameHandler.cjs +1 -1
  112. package/dist/utils/Type.cjs +2 -1
  113. package/dist/utils/TypesHandler.cjs +55 -0
  114. package/dist/utils/UtilsConst.cjs +101 -0
  115. package/dist/utils/connectionData/IConnectionData.cjs +9 -0
  116. package/dist/utils/connectionData/InMemoryConnectionData.cjs +10 -0
  117. package/dist/utils/connectionData/WsConnectionData.cjs +4 -0
  118. package/dist/utils/nodejs/connectionData/TcpConnectionData.cjs +33 -3
  119. package/lib/core/delegatesCache/DelegatesCache.js +1 -0
  120. package/lib/core/handler/AbstractHandler.js +27 -9
  121. package/lib/core/handler/ArrayGetItemHandler.js +9 -1
  122. package/lib/core/handler/ArrayGetRankHandler.js +9 -0
  123. package/lib/core/handler/ArrayGetSizeHandler.js +8 -0
  124. package/lib/core/handler/ArrayHandler.js +8 -0
  125. package/lib/core/handler/ArraySetItemHandler.js +11 -1
  126. package/lib/core/handler/CastingHandler.js +8 -1
  127. package/lib/core/handler/ConvertTypeHandler.js +9 -4
  128. package/lib/core/handler/CreateClassInstanceHandler.js +10 -4
  129. package/lib/core/handler/DestructReferenceHandler.js +8 -0
  130. package/lib/core/handler/EnableNamespaceHandler.js +8 -0
  131. package/lib/core/handler/EnableTypeHandler.js +8 -0
  132. package/lib/core/handler/GetGlobalStaticFieldHandler.js +9 -0
  133. package/lib/core/handler/GetInstanceFieldHandler.js +8 -0
  134. package/lib/core/handler/GetInstanceMethodAsDelegateHandler.js +9 -4
  135. package/lib/core/handler/GetStaticFieldHandler.js +9 -0
  136. package/lib/core/handler/GetStaticMethodAsDelegateHandler.js +8 -7
  137. package/lib/core/handler/GetTypeHandler.js +15 -5
  138. package/lib/core/handler/Handler.js +13 -18
  139. package/lib/core/handler/InvokeDelegateHandler.js +5 -0
  140. package/lib/core/handler/InvokeGlobalFunctionHandler.js +11 -1
  141. package/lib/core/handler/InvokeInstanceMethodHandler.js +8 -0
  142. package/lib/core/handler/InvokeStaticMethodHandler.js +8 -0
  143. package/lib/core/handler/LoadLibraryHandler.js +11 -0
  144. package/lib/core/handler/SetGlobalStaticFieldHandler.js +10 -0
  145. package/lib/core/handler/SetInstanceFieldHandler.js +7 -0
  146. package/lib/core/handler/SetStaticFieldHandler.js +8 -0
  147. package/lib/core/handler/ValueHandler.js +9 -0
  148. package/lib/core/interpreter/Interpreter.js +42 -24
  149. package/lib/core/namespaceCache/NamespaceCache.js +14 -0
  150. package/lib/core/protocol/CommandDeserializer.js +11 -2
  151. package/lib/core/protocol/CommandSerializer.js +40 -9
  152. package/lib/core/protocol/TypeDeserializer.js +36 -0
  153. package/lib/core/protocol/TypeSerializer.js +62 -7
  154. package/lib/core/receiver/Receiver.js +3 -2
  155. package/lib/core/receiver/ReceiverNative.js +8 -0
  156. package/lib/core/transmitter/Transmitter.js +18 -1
  157. package/lib/core/transmitter/TransmitterWebsocket.js +12 -5
  158. package/lib/core/transmitter/TransmitterWebsocketBrowser.js +2 -4
  159. package/lib/core/transmitter/TransmitterWrapper.js +27 -6
  160. package/lib/core/typeCache/TypeCache.js +9 -0
  161. package/lib/core/webSocketClient/WebSocketClient.js +33 -30
  162. package/lib/core/webSocketClient/WebSocketClientBrowser.js +5 -6
  163. package/lib/sdk/ConfigRuntimeFactory.js +70 -68
  164. package/lib/sdk/InvocationContext.js +94 -26
  165. package/lib/sdk/Javonet.js +18 -36
  166. package/lib/sdk/RuntimeContext.js +109 -29
  167. package/lib/sdk/RuntimeFactory.js +7 -0
  168. package/lib/sdk/tools/ActivationHelper.js +51 -0
  169. package/lib/sdk/tools/JsonResolver.js +226 -0
  170. package/lib/types.d.ts +57 -0
  171. package/lib/utils/Command.js +14 -9
  172. package/lib/utils/CustomError.js +5 -0
  173. package/lib/utils/Runtime.js +1 -1
  174. package/lib/utils/RuntimeLogger.js +3 -0
  175. package/lib/utils/RuntimeNameHandler.js +6 -1
  176. package/lib/utils/Type.js +2 -1
  177. package/lib/utils/TypesHandler.js +35 -0
  178. package/lib/utils/UtilsConst.js +88 -0
  179. package/lib/utils/connectionData/IConnectionData.js +14 -0
  180. package/lib/utils/connectionData/InMemoryConnectionData.js +15 -0
  181. package/lib/utils/connectionData/WsConnectionData.js +9 -0
  182. package/lib/utils/nodejs/connectionData/TcpConnectionData.js +35 -5
  183. package/package.json +4 -3
  184. package/dist/sdk/tools/browser/ConfigSourceResolver.cjs +0 -153
  185. package/dist/sdk/tools/nodejs/JsonFileResolver.cjs +0 -120
  186. package/dist/types/sdk/tools/browser/ConfigSourceResolver.d.ts +0 -46
  187. package/dist/types/sdk/tools/nodejs/JsonFileResolver.d.ts +0 -13
  188. package/dist/types/utils/nodejs/TypesConverter.d.ts +0 -48
  189. package/dist/utils/nodejs/TypesConverter.cjs +0 -102
  190. package/lib/declarations.d.ts +0 -35
  191. package/lib/sdk/tools/browser/ConfigSourceResolver.js +0 -146
  192. package/lib/sdk/tools/nodejs/JsonFileResolver.js +0 -106
  193. package/lib/utils/nodejs/TypesConverter.js +0 -91
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)
@@ -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'
@@ -42,7 +42,7 @@ export function getRuntimeExtension() {
42
42
  /**
43
43
  * Get the require function
44
44
  * @param {string} callerPath - The path to the caller
45
- * @returns {import('module').createRequire}
45
+ * @returns {any}
46
46
  */
47
47
  export const getRequire = (callerPath) => {
48
48
  try {
@@ -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
  }
@@ -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
  * Represents WebSocket connection data.
6
11
  * @extends IConnectionData
@@ -40,6 +45,10 @@ class WsConnectionData extends IConnectionData {
40
45
  return [this.connectionType, 0, 0, 0, 0, 0, 0]
41
46
  }
42
47
 
48
+ /**
49
+ * @param {WsConnectionData} other
50
+ * @returns {boolean}
51
+ */
43
52
  equals(other) {
44
53
  return other instanceof WsConnectionData && this._hostname === other.hostname
45
54
  }
@@ -1,12 +1,28 @@
1
+ // @ts-check
1
2
  import { IConnectionData } from '../../connectionData/IConnectionData.js'
2
3
  import { ConnectionType } from '../../ConnectionType.js'
3
4
  import { getRequire, isNodejsRuntime } from '../../Runtime.js'
4
5
 
5
6
  const requireDynamic = getRequire(import.meta.url)
7
+
6
8
  /**
9
+ * @typedef {import('../../ConnectionType.js').ConnectionType} ConnectionType
7
10
  * @extends IConnectionData
8
11
  */
9
12
  export class TcpConnectionData extends IConnectionData {
13
+ /** @type {string} */
14
+ ipAddress = ''
15
+ /** @type {number} */
16
+ _port = 0
17
+ /** @type {string} */
18
+ _hostname = ''
19
+ /** @type {ConnectionType} */
20
+ _connectionType = ConnectionType.TCP
21
+
22
+ /**
23
+ * @param {string} hostname
24
+ * @param {number} port
25
+ */
10
26
  constructor(hostname, port) {
11
27
  super()
12
28
  this._port = port
@@ -19,6 +35,9 @@ export class TcpConnectionData extends IConnectionData {
19
35
  }
20
36
  }
21
37
 
38
+ /**
39
+ * @returns {ConnectionType}
40
+ */
22
41
  get connectionType() {
23
42
  return this._connectionType
24
43
  }
@@ -40,7 +59,7 @@ export class TcpConnectionData extends IConnectionData {
40
59
 
41
60
  /**
42
61
  * @param {string} hostname
43
- * @returns {string|null}
62
+ * @returns {string}
44
63
  */
45
64
  resolveIpAddress(hostname) {
46
65
  try {
@@ -54,24 +73,29 @@ export class TcpConnectionData extends IConnectionData {
54
73
  const dns = requireDynamic('dns')
55
74
 
56
75
  // If it's not an IP address, try to resolve it as a hostname
57
- return dns.resolve4(hostname, (err, addresses) => {
76
+ return dns.resolve4(hostname, (/** @type {Error | null} */ err, /** @type {string[]} */ addresses) => {
58
77
  if (err) {
59
78
  console.error(err)
60
- return null
79
+ return ''
61
80
  }
62
81
  return addresses[0]
63
82
  })
64
- // eslint-disable-next-line no-unused-vars
65
83
  }
66
84
  }
85
+ return ''
67
86
  } catch (error) {
68
- if (error.code === 'MODULE_NOT_FOUND') {
87
+ const err = /** @type {{code?: string}} */ (error)
88
+ if (err.code === 'MODULE_NOT_FOUND') {
69
89
  throw new Error('dns module not found. Please install it using npm install dns')
70
90
  }
71
91
  throw error
72
92
  }
73
93
  }
74
94
 
95
+ /**
96
+ * Serializes the connection data.
97
+ * @returns {number[]} An array of connection data values.
98
+ */
75
99
  serializeConnectionData() {
76
100
  let result = [this.connectionType]
77
101
  result = result.concat(this.#getAddressBytes())
@@ -79,10 +103,16 @@ export class TcpConnectionData extends IConnectionData {
79
103
  return result
80
104
  }
81
105
 
106
+ /**
107
+ * @returns {number[]} An array of address bytes.
108
+ */
82
109
  #getAddressBytes() {
83
110
  return this.ipAddress.split('.').map(Number)
84
111
  }
85
112
 
113
+ /**
114
+ * @returns {number[]} An array of port bytes.
115
+ */
86
116
  #getPortBytes() {
87
117
  return [this._port & 0xff, this._port >> 8]
88
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javonet-nodejs-sdk",
3
- "version": "2.5.17",
3
+ "version": "2.5.18",
4
4
  "description": "Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology. It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products. Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today! For more information check out our guides at https://www.javonet.com/guides/v2/",
5
5
  "keywords": [],
6
6
  "author": "SdNCenter Sp. z o. o.",
@@ -42,6 +42,7 @@
42
42
  "format": "prettier --write ."
43
43
  },
44
44
  "dependencies": {
45
+ "@types/ws": "^8.18.1",
45
46
  "buffer": "^6.0.3",
46
47
  "glob": "^10.4.5",
47
48
  "uuid": "^10.0.0"
@@ -78,8 +79,8 @@
78
79
  "peerDependencies": {
79
80
  "crypto": "^1.0.1",
80
81
  "dns": "^0.2.2",
81
- "ws": "^8.0.0",
82
- "fs-extra": "^11.2.0"
82
+ "fs-extra": "^11.2.0",
83
+ "ws": "^8.0.0"
83
84
  },
84
85
  "peerDependenciesMeta": {
85
86
  "ws": {
@@ -1,153 +0,0 @@
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 ConfigSourceResolver_exports = {};
20
- __export(ConfigSourceResolver_exports, {
21
- ConfigSourceResolver: () => ConfigSourceResolver
22
- });
23
- module.exports = __toCommonJS(ConfigSourceResolver_exports);
24
- function hasOwnProperty(obj, key) {
25
- return Object.prototype.hasOwnProperty.call(obj, key);
26
- }
27
- class ConfigSourceResolver {
28
- /**
29
- *
30
- * @param {object | string} configSource
31
- */
32
- constructor(configSource) {
33
- if (typeof configSource === "string") {
34
- try {
35
- this.jsonObject = JSON.parse(configSource);
36
- } catch (err) {
37
- throw new Error(
38
- `Failed to parse configSource as JSON: ${err instanceof Error ? err.message : "Unknown error"}`
39
- );
40
- }
41
- } else if (configSource && typeof configSource === "object") {
42
- this.jsonObject = configSource;
43
- } else {
44
- throw new Error("configSource must be a JSON object or JSON string");
45
- }
46
- }
47
- getLicenseKey() {
48
- if (!hasOwnProperty(this.jsonObject, "licenseKey")) {
49
- throw new Error(
50
- "License key not found in configuration file. Please check your configuration file."
51
- );
52
- }
53
- return this.jsonObject.licenseKey;
54
- }
55
- getRuntimes() {
56
- return this.jsonObject.runtimes;
57
- }
58
- /**
59
- * @param {string} runtimeName
60
- * @param {string} configName
61
- * @returns {any}
62
- */
63
- getRuntime(runtimeName, configName) {
64
- const runtimes = this.getRuntimes();
65
- if (hasOwnProperty(runtimes, runtimeName)) {
66
- const runtime = runtimes[runtimeName];
67
- if (Array.isArray(runtime)) {
68
- for (let item of runtime) {
69
- if (item.name === configName) {
70
- return item;
71
- }
72
- }
73
- } else if (runtime?.name === configName) {
74
- return runtime;
75
- }
76
- }
77
- throw new Error(
78
- `Runtime config ${configName} not found in configuration file for runtime ${runtimeName}. Please check your configuration file.`
79
- );
80
- }
81
- /**
82
- * @param {string} runtimeName
83
- * @param {string} configName
84
- * @returns {any}
85
- */
86
- getChannel(runtimeName, configName) {
87
- const runtime = this.getRuntime(runtimeName, configName);
88
- if (!hasOwnProperty(runtime, "channel")) {
89
- throw new Error(
90
- `Channel key not found in configuration file for config ${configName}. Please check your configuration file.`
91
- );
92
- }
93
- return runtime.channel;
94
- }
95
- /**
96
- * @param {string} runtimeName
97
- * @param {string} configName
98
- * @returns {any}
99
- */
100
- getChannelType(runtimeName, configName) {
101
- const channel = this.getChannel(runtimeName, configName);
102
- if (!hasOwnProperty(channel, "type")) {
103
- throw new Error(
104
- `Channel type not found in configuration file for config ${configName}. Please check your configuration file.`
105
- );
106
- }
107
- return channel.type;
108
- }
109
- /**
110
- * @param {string} runtimeName
111
- * @param {string} configName
112
- * @returns {any}
113
- */
114
- getChannelHost(runtimeName, configName) {
115
- const channel = this.getChannel(runtimeName, configName);
116
- if (!hasOwnProperty(channel, "host")) {
117
- throw new Error(
118
- `Channel host not found in configuration file for config ${configName}. Please check your configuration file.`
119
- );
120
- }
121
- return channel.host;
122
- }
123
- /**
124
- * @param {string} runtimeName
125
- * @param {string} configName
126
- * @returns {any}
127
- */
128
- getChannelPort(runtimeName, configName) {
129
- const channel = this.getChannel(runtimeName, configName);
130
- if (!hasOwnProperty(channel, "port")) {
131
- throw new Error(
132
- `Channel port not found in configuration file for config ${configName}. Please check your configuration file.`
133
- );
134
- }
135
- return channel.port;
136
- }
137
- /**
138
- * @param {string} runtimeName
139
- * @param {string} configName
140
- * @returns {any}
141
- */
142
- getModules(runtimeName, configName) {
143
- const runtime = this.getRuntime(runtimeName, configName);
144
- if (hasOwnProperty(runtime, "modules")) {
145
- return runtime.modules;
146
- }
147
- return "";
148
- }
149
- }
150
- // Annotate the CommonJS export names for ESM import in node:
151
- 0 && (module.exports = {
152
- ConfigSourceResolver
153
- });