javonet-nodejs-sdk 2.6.6 → 2.6.8

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 (45) hide show
  1. package/dist/core/handler/Handler.cjs +2 -7
  2. package/dist/core/handler/LoadLibraryHandler.cjs +26 -12
  3. package/dist/core/handler/PassDelegateHandler.cjs +2 -2
  4. package/dist/core/interpreter/Interpreter.cjs +27 -92
  5. package/dist/core/protocol/CommandSerializer.cjs +3 -8
  6. package/dist/core/receiver/Receiver.cjs +6 -6
  7. package/dist/sdk/Activator.cjs +44 -0
  8. package/dist/sdk/ActivatorDetails.cjs +13 -3
  9. package/dist/sdk/ConfigRuntimeFactory.cjs +9 -0
  10. package/dist/sdk/InvocationContext.cjs +52 -200
  11. package/dist/sdk/Javonet.cjs +3 -11
  12. package/dist/sdk/RuntimeContext.cjs +11 -57
  13. package/dist/sdk/configuration/ConfigSourceResolver.cjs +43 -21
  14. package/dist/sdk/tools/ComplexTypeResolver.cjs +84 -45
  15. package/dist/types/core/handler/Handler.d.ts +2 -1
  16. package/dist/types/core/handler/PassDelegateHandler.d.ts +2 -2
  17. package/dist/types/core/interpreter/Interpreter.d.ts +2 -9
  18. package/dist/types/core/protocol/CommandSerializer.d.ts +3 -3
  19. package/dist/types/core/receiver/Receiver.d.ts +4 -4
  20. package/dist/types/sdk/Activator.d.ts +12 -0
  21. package/dist/types/sdk/ActivatorDetails.d.ts +5 -3
  22. package/dist/types/sdk/ConfigRuntimeFactory.d.ts +7 -0
  23. package/dist/types/sdk/InvocationContext.d.ts +11 -34
  24. package/dist/types/sdk/Javonet.d.ts +3 -1
  25. package/dist/types/sdk/RuntimeContext.d.ts +4 -3
  26. package/dist/types/sdk/configuration/ConfigSourceResolver.d.ts +21 -4
  27. package/dist/types/sdk/tools/ComplexTypeResolver.d.ts +21 -5
  28. package/dist/types/utils/Primitives.d.ts +5 -0
  29. package/dist/utils/Primitives.cjs +201 -0
  30. package/lib/core/handler/Handler.js +2 -7
  31. package/lib/core/handler/LoadLibraryHandler.js +43 -15
  32. package/lib/core/handler/PassDelegateHandler.js +2 -2
  33. package/lib/core/interpreter/Interpreter.js +38 -104
  34. package/lib/core/protocol/CommandSerializer.js +5 -10
  35. package/lib/core/receiver/Receiver.js +6 -6
  36. package/lib/sdk/Activator.js +22 -0
  37. package/lib/sdk/ActivatorDetails.js +18 -3
  38. package/lib/sdk/ConfigRuntimeFactory.js +10 -0
  39. package/lib/sdk/InvocationContext.js +54 -205
  40. package/lib/sdk/Javonet.js +2 -14
  41. package/lib/sdk/RuntimeContext.js +14 -59
  42. package/lib/sdk/configuration/ConfigSourceResolver.js +47 -14
  43. package/lib/sdk/tools/ComplexTypeResolver.js +104 -43
  44. package/lib/utils/Primitives.js +193 -0
  45. package/package.json +1 -12
@@ -1,13 +1,14 @@
1
1
  //@ts-check
2
+ import { PrimitiveSet } from '../../utils/Primitives.js'
2
3
  import { getRequire } from '../../utils/Runtime.js'
3
4
  import { RuntimeName } from '../../utils/RuntimeName.js'
5
+ import { Activator } from '../Activator.js'
4
6
  import { ActivatorDetails } from '../ActivatorDetails.js'
5
7
  import { InvocationContext } from '../InvocationContext.js'
6
8
  import { JavaTypeParsingFunctions } from './typeParsingFunctions/JavaTypeParsingFunctions.js'
7
9
  import { NetcoreTypeParsingFunctions } from './typeParsingFunctions/NetcoreTypeParsingFunctions.js'
8
10
  import { NodejsTypeParsingFunctions } from './typeParsingFunctions/NodejsTypeParsingFunctions.js'
9
11
  import { PythonTypeParsingFunctions } from './typeParsingFunctions/PythonTypeParsingFunctions.js'
10
- import * as util from 'node:util'
11
12
 
12
13
  const dynamicImport = getRequire(import.meta.url)
13
14
 
@@ -15,19 +16,23 @@ const dynamicImport = getRequire(import.meta.url)
15
16
  * @typedef {import('../../types.d.ts').RuntimeName} RuntimeName
16
17
  */
17
18
 
19
+ /** @type {Map<number, Map<string, Function>>} */
20
+ const typeParsingFunctions = new Map([
21
+ [RuntimeName.Netcore, NetcoreTypeParsingFunctions],
22
+ [RuntimeName.Jvm, JavaTypeParsingFunctions],
23
+ [RuntimeName.Nodejs, NodejsTypeParsingFunctions],
24
+ [RuntimeName.Python, PythonTypeParsingFunctions],
25
+ [RuntimeName.Python27, PythonTypeParsingFunctions],
26
+ ])
27
+
18
28
  class ComplexTypeResolver {
19
29
  /** @type {Map<string, ActivatorDetails>} */
20
- #typeMap = new Map()
21
-
22
- /** @type {Map<number, Map<string, Function>>} */
23
- #typeParsingFunctions = new Map([
24
- [RuntimeName.Netcore, NetcoreTypeParsingFunctions],
25
- [RuntimeName.Jvm, JavaTypeParsingFunctions],
26
- [RuntimeName.Nodejs, NodejsTypeParsingFunctions],
27
- [RuntimeName.Python, PythonTypeParsingFunctions],
28
- [RuntimeName.Python27, PythonTypeParsingFunctions],
29
- ])
30
-
30
+ #typeMap
31
+
32
+ constructor() {
33
+ this.#typeMap = new Map()
34
+ }
35
+
31
36
  /**
32
37
  * Register a custom type mapping
33
38
  * @param {string} resultType - The type name from the target runtime
@@ -43,46 +48,47 @@ class ComplexTypeResolver {
43
48
  /**
44
49
  * Convert InvocationContext result to appropriate JavaScript type
45
50
  * @param {InvocationContext} ic - The invocation context
46
- * @returns {Promise<any> | any} The converted result
51
+ * @returns {Promise<any>} The converted result
47
52
  */
48
- convertResult(ic) {
53
+ async convertResult(ic) {
49
54
  const runtimeName = ic.getRuntimeName()
50
- const resultType = ic.getResultType()
51
-
52
- // Try built-in type parsing functions first
53
- const runtimeDict = this.#typeParsingFunctions.get(runtimeName)
54
- if (runtimeDict) {
55
- let parsingFunc = null;
56
- if (resultType instanceof Promise) {
57
- parsingFunc = resultType.then(result => {
58
- parsingFunc = runtimeDict.get(result);
59
- })
60
- } else {
61
- parsingFunc = runtimeDict.get(resultType);
62
- }
55
+ const resultType = await ic.getResultType()
63
56
 
64
- if (parsingFunc) {
65
- // @ts-ignore
66
- return parsingFunc(ic)
67
- }
57
+ if (!resultType) {
58
+ throw new Error('resultType is not valid')
59
+ }
60
+
61
+ let underlyingType = ComplexTypeResolver.tryGetUnderlyingArrayType(resultType)
62
+ if (underlyingType !== null) {
63
+ const { Type } = /** @type {ActivatorDetails} */ (this.#typeMap.get(underlyingType))
64
+
65
+ const complexTypesArray = await ic.retrieveArray()
66
+ return complexTypesArray.map((item) => Activator.createInstance(Type, item))
68
67
  }
69
68
 
70
- // Try registered custom types
71
- let activatorDetails = null;
72
- if (resultType instanceof Promise) {
73
- activatorDetails = resultType.then(result => {
74
- activatorDetails = this.#typeMap.get(result);
75
- })
76
- } else {
77
- activatorDetails = this.#typeMap.get(resultType);
69
+ const parsingFunction = ComplexTypeResolver.tryGetTypeParsingFunction(runtimeName, resultType)
70
+ if (parsingFunction) {
71
+ return parsingFunction(ic)
78
72
  }
79
73
 
74
+ const activatorDetails = this.tryGetValueFromTypeMap(resultType)
80
75
  if (!activatorDetails) {
81
76
  throw new Error(`No type registered for key '${resultType}'.`)
82
77
  }
83
-
84
- // @ts-ignore
85
- return new /** @type {any} */ (activatorDetails.type)(...activatorDetails.arguments)
78
+
79
+ // For nodejs inmemory, getValue() returns the actual JS object
80
+ if (runtimeName === RuntimeName.Nodejs) {
81
+ const value = await ic.getValue()
82
+ if (value) {
83
+ // If it's already an instance of the registered type, return it directly
84
+ if (value instanceof activatorDetails.Type) {
85
+ return value
86
+ }
87
+ }
88
+ }
89
+
90
+ // Create new instance with stored default arguments
91
+ return Activator.createInstance(activatorDetails.Type, activatorDetails.arguments ?? null)
86
92
  }
87
93
 
88
94
  /**
@@ -117,6 +123,61 @@ class ComplexTypeResolver {
117
123
  }
118
124
  return typeObj
119
125
  }
120
- }
121
126
 
127
+ /**
128
+ * Attempts to extract the underlying element type from an array type string
129
+ * @param {string} type - The type string to parse (e.g., "MyType[]")
130
+ * @returns {string | null} Object indicating success and the element type
131
+ * @throws {Error} If the array element type is a primitive type
132
+ */
133
+ static tryGetUnderlyingArrayType(type) {
134
+ // Validate input type
135
+ if (typeof type !== 'string' || !type.includes('[')) {
136
+ return null
137
+ }
138
+
139
+ let trimmedType = type.trim()
140
+ if (!trimmedType) return null
141
+
142
+ // If assembly-qualified, remove everything after the first comma
143
+ const commaIndex = trimmedType.indexOf(',')
144
+ if (commaIndex > 0) {
145
+ trimmedType = trimmedType.substring(0, commaIndex).trim()
146
+ }
147
+
148
+ // Find the first '[' — everything before it is the base type
149
+ const bracketIndex = trimmedType.indexOf('[')
150
+ if (bracketIndex > 0) {
151
+ trimmedType = trimmedType.substring(0, bracketIndex).trim()
152
+ }
153
+
154
+ // Check if base type is a primitive (primitives are not supported as array elements)
155
+ if (PrimitiveSet.has(trimmedType)) {
156
+ throw new Error('Primitive array element types are not supported.')
157
+ }
158
+
159
+ return trimmedType
160
+ }
161
+
162
+ /**
163
+ * @param {RuntimeName} runtimeName
164
+ * @param {string} resultType
165
+ * @returns {any}
166
+ */
167
+ static tryGetTypeParsingFunction(runtimeName, resultType) {
168
+ const runtimeDict = typeParsingFunctions.get(runtimeName)
169
+ return runtimeDict ? (runtimeDict.get(resultType) ?? null) : null
170
+ }
171
+
172
+ /**
173
+ * @param {string} resultType
174
+ * @returns {ActivatorDetails | null}
175
+ */
176
+ tryGetValueFromTypeMap(resultType) {
177
+ if (!resultType) {
178
+ throw new Error('resultType is not valid')
179
+ }
180
+ return this.#typeMap.get(resultType) ?? null
181
+ }
182
+ }
122
183
  export { ComplexTypeResolver }
@@ -0,0 +1,193 @@
1
+ // @ts-check
2
+ /**
3
+ * Set of primitive type names that are not supported as array element types
4
+ * @type {Set<string>}
5
+ */
6
+ export const PrimitiveSet = new Set(
7
+ [
8
+ // --- JavaScript / TypeScript ---
9
+ 'string',
10
+ 'number',
11
+ 'boolean',
12
+ 'bigint',
13
+ 'symbol',
14
+ 'undefined',
15
+ 'null',
16
+
17
+ // --- .NET / C# ---
18
+ 'bool',
19
+ 'boolean',
20
+ 'byte',
21
+ 'sbyte',
22
+ 'char',
23
+ 'decimal',
24
+ 'double',
25
+ 'float',
26
+ 'single',
27
+ 'int',
28
+ 'int32',
29
+ 'uint',
30
+ 'uint32',
31
+ 'long',
32
+ 'int64',
33
+ 'ulong',
34
+ 'uint64',
35
+ 'short',
36
+ 'int16',
37
+ 'ushort',
38
+ 'uint16',
39
+ 'object',
40
+ 'string',
41
+ 'system.boolean',
42
+ 'system.byte',
43
+ 'system.sbyte',
44
+ 'system.char',
45
+ 'system.decimal',
46
+ 'system.double',
47
+ 'system.single',
48
+ 'system.int',
49
+ 'system.int32',
50
+ 'system.uint',
51
+ 'system.uint32',
52
+ 'system.int64',
53
+ 'system.uint64',
54
+ 'system.int16',
55
+ 'system.uint16',
56
+ 'system.object',
57
+ 'system.string',
58
+
59
+ // --- Java ---
60
+ 'byte',
61
+ 'short',
62
+ 'int',
63
+ 'long',
64
+ 'float',
65
+ 'double',
66
+ 'char',
67
+ 'boolean',
68
+ 'java.lang.string',
69
+
70
+ // --- Python ---
71
+ 'str',
72
+ 'int',
73
+ 'float',
74
+ 'bool',
75
+ 'bytes',
76
+ 'bytearray',
77
+
78
+ // --- Go ---
79
+ 'rune',
80
+ 'byte',
81
+ 'bool',
82
+ 'string',
83
+ 'int',
84
+ 'int8',
85
+ 'int16',
86
+ 'int32',
87
+ 'int64',
88
+ 'uint',
89
+ 'uint8',
90
+ 'uint16',
91
+ 'uint32',
92
+ 'uint64',
93
+ 'float32',
94
+ 'float64',
95
+
96
+ // --- C / C++ ---
97
+ 'char',
98
+ 'short',
99
+ 'int',
100
+ 'long',
101
+ 'float',
102
+ 'double',
103
+ 'signed char',
104
+ 'unsigned char',
105
+ 'unsigned short',
106
+ 'unsigned int',
107
+ 'unsigned long',
108
+
109
+ // --- Rust ---
110
+ 'bool',
111
+ 'u8',
112
+ 'i8',
113
+ 'u16',
114
+ 'i16',
115
+ 'u32',
116
+ 'i32',
117
+ 'u64',
118
+ 'i64',
119
+ 'f32',
120
+ 'f64',
121
+ 'usize',
122
+ 'isize',
123
+ 'str',
124
+
125
+ // --- Kotlin ---
126
+ 'boolean',
127
+ 'byte',
128
+ 'short',
129
+ 'int',
130
+ 'long',
131
+ 'float',
132
+ 'double',
133
+ 'char',
134
+ 'string',
135
+
136
+ // --- Swift ---
137
+ 'bool',
138
+ 'int',
139
+ 'uint',
140
+ 'float',
141
+ 'double',
142
+ 'string',
143
+ 'character',
144
+
145
+ // --- PHP ---
146
+ 'int',
147
+ 'integer',
148
+ 'float',
149
+ 'double',
150
+ 'string',
151
+ 'bool',
152
+ 'boolean',
153
+ 'mixed',
154
+
155
+ // --- Ruby ---
156
+ 'string',
157
+ 'integer',
158
+ 'fixnum',
159
+ 'float',
160
+ 'symbol',
161
+ 'boolean',
162
+
163
+ // --- Dart ---
164
+ 'int',
165
+ 'double',
166
+ 'num',
167
+ 'bool',
168
+ 'string',
169
+
170
+ // --- Scala ---
171
+ 'int',
172
+ 'long',
173
+ 'double',
174
+ 'float',
175
+ 'char',
176
+ 'boolean',
177
+ 'string',
178
+
179
+ // --- Haskell ---
180
+ 'int',
181
+ 'float',
182
+ 'double',
183
+ 'char',
184
+ 'bool',
185
+ 'integer',
186
+
187
+ // --- Generic aliases ---
188
+ 'text',
189
+ 'primitive',
190
+ 'any',
191
+ 'void',
192
+ ].map((x) => x.toLowerCase())
193
+ )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javonet-nodejs-sdk",
3
- "version": "2.6.6",
3
+ "version": "2.6.8",
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.",
@@ -30,17 +30,6 @@
30
30
  "default": "./lib/utils/CreateRequire.node.js"
31
31
  }
32
32
  },
33
- "jest": {
34
- "verbose": true,
35
- "testResultsProcessor": "./node_modules/jest-junit-reporter",
36
- "coverageReporters": [
37
- "json",
38
- "lcov",
39
- "text",
40
- "clover",
41
- "cobertura"
42
- ]
43
- },
44
33
  "scripts": {
45
34
  "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/unitTests tests/functional -t=\"(Unit|Functional)\" --maxWorkers=3 --colors --coverage",
46
35
  "webserviceTests": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/webSocketClientTests --maxWorkers=3 --colors",