javonet-nodejs-sdk 2.6.7 → 2.6.9
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.
- package/dist/core/handler/CreateClassInstanceHandler.cjs +35 -1
- package/dist/core/handler/Handler.cjs +28 -9
- package/dist/core/handler/LoadLibraryHandler.cjs +15 -9
- package/dist/core/handler/PassDelegateHandler.cjs +2 -2
- package/dist/core/interpreter/Interpreter.cjs +11 -33
- package/dist/core/protocol/CommandSerializer.cjs +3 -8
- package/dist/core/receiver/Receiver.cjs +6 -6
- package/dist/sdk/Activator.cjs +44 -0
- package/dist/sdk/ActivatorDetails.cjs +13 -3
- package/dist/sdk/ConfigRuntimeFactory.cjs +9 -0
- package/dist/sdk/InvocationContext.cjs +112 -66
- package/dist/sdk/Javonet.cjs +3 -0
- package/dist/sdk/RuntimeContext.cjs +8 -8
- package/dist/sdk/configuration/ConfigSourceResolver.cjs +43 -21
- package/dist/sdk/tools/ComplexTypeResolver.cjs +84 -34
- package/dist/types/core/handler/CreateClassInstanceHandler.d.ts +8 -0
- package/dist/types/core/handler/Handler.d.ts +2 -1
- package/dist/types/core/handler/PassDelegateHandler.d.ts +2 -2
- package/dist/types/core/interpreter/Interpreter.d.ts +2 -2
- package/dist/types/core/protocol/CommandSerializer.d.ts +3 -3
- package/dist/types/core/receiver/Receiver.d.ts +4 -4
- package/dist/types/sdk/Activator.d.ts +12 -0
- package/dist/types/sdk/ActivatorDetails.d.ts +5 -3
- package/dist/types/sdk/ConfigRuntimeFactory.d.ts +7 -0
- package/dist/types/sdk/InvocationContext.d.ts +19 -17
- package/dist/types/sdk/Javonet.d.ts +2 -1
- package/dist/types/sdk/RuntimeContext.d.ts +4 -3
- package/dist/types/sdk/configuration/ConfigSourceResolver.d.ts +21 -4
- package/dist/types/sdk/tools/ComplexTypeResolver.d.ts +21 -5
- package/dist/types/utils/CommandType.d.ts +1 -0
- package/dist/types/utils/Primitives.d.ts +5 -0
- package/dist/utils/CommandType.cjs +2 -1
- package/dist/utils/Primitives.cjs +201 -0
- package/lib/core/handler/CreateClassInstanceHandler.js +46 -1
- package/lib/core/handler/Handler.js +34 -9
- package/lib/core/handler/LoadLibraryHandler.js +28 -14
- package/lib/core/handler/PassDelegateHandler.js +2 -2
- package/lib/core/interpreter/Interpreter.js +11 -35
- package/lib/core/protocol/CommandSerializer.js +5 -10
- package/lib/core/receiver/Receiver.js +6 -6
- package/lib/sdk/Activator.js +22 -0
- package/lib/sdk/ActivatorDetails.js +18 -3
- package/lib/sdk/ConfigRuntimeFactory.js +10 -0
- package/lib/sdk/InvocationContext.js +133 -74
- package/lib/sdk/Javonet.js +2 -0
- package/lib/sdk/RuntimeContext.js +8 -8
- package/lib/sdk/configuration/ConfigSourceResolver.js +47 -14
- package/lib/sdk/tools/ComplexTypeResolver.js +104 -42
- package/lib/utils/CommandType.js +1 -0
- package/lib/utils/Primitives.js +193 -0
- package/package.json +4 -3
|
@@ -7,9 +7,9 @@ export class Interpreter {
|
|
|
7
7
|
*
|
|
8
8
|
* @param {Command} command
|
|
9
9
|
* @param {IConnectionData} connectionData
|
|
10
|
-
* @returns {
|
|
10
|
+
* @returns {Promise<Command>}
|
|
11
11
|
*/
|
|
12
|
-
execute(command: Command, connectionData: IConnectionData):
|
|
12
|
+
execute(command: Command, connectionData: IConnectionData): Promise<Command>;
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
15
15
|
* @param {Uint8Array} messageByteArray
|
|
@@ -5,12 +5,12 @@ export type IConnectionData = import("../../utils/connectionData/IConnectionData
|
|
|
5
5
|
export class CommandSerializer {
|
|
6
6
|
/**
|
|
7
7
|
* Serializes the root command with connection data and optional runtime version.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {Command} rootCommand
|
|
9
9
|
* @param {IConnectionData} connectionData
|
|
10
10
|
* @param {number} runtimeVersion
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {Uint8Array}
|
|
12
12
|
*/
|
|
13
|
-
serialize(rootCommand:
|
|
13
|
+
serialize(rootCommand: Command, connectionData: IConnectionData, runtimeVersion?: number): Uint8Array;
|
|
14
14
|
/**
|
|
15
15
|
* Recursively serializes command payload.
|
|
16
16
|
* @param {Command} command
|
|
@@ -3,14 +3,14 @@ export class Receiver {
|
|
|
3
3
|
static getRuntimeInfo(): string;
|
|
4
4
|
/**
|
|
5
5
|
* @param {Uint8Array} messageByteArray
|
|
6
|
-
* @returns {Promise<Uint8Array>
|
|
6
|
+
* @returns {Promise<Uint8Array>}
|
|
7
7
|
*/
|
|
8
|
-
static sendCommand(messageByteArray: Uint8Array): Promise<Uint8Array
|
|
8
|
+
static sendCommand(messageByteArray: Uint8Array): Promise<Uint8Array>;
|
|
9
9
|
/**
|
|
10
10
|
* @param {Uint8Array} messageByteArray
|
|
11
|
-
* @returns {Promise<Uint8Array>
|
|
11
|
+
* @returns {Promise<Uint8Array>}
|
|
12
12
|
*/
|
|
13
|
-
static heartBeat(messageByteArray: Uint8Array): Promise<Uint8Array
|
|
13
|
+
static heartBeat(messageByteArray: Uint8Array): Promise<Uint8Array>;
|
|
14
14
|
Receiver(): void;
|
|
15
15
|
}
|
|
16
16
|
import { InMemoryConnectionData } from '../../utils/connectionData/InMemoryConnectionData.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Details for activating a type with constructor arguments
|
|
3
|
+
*/
|
|
4
|
+
export class Activator {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new instance of a type
|
|
7
|
+
* @param {Function} Type - The constructor function/class
|
|
8
|
+
* @param {any[] | any} args - The arguments to pass to the constructor
|
|
9
|
+
* @returns {any} The new instance
|
|
10
|
+
*/
|
|
11
|
+
static createInstance(Type: Function, args: any[] | any): any;
|
|
12
|
+
}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
export class ActivatorDetails {
|
|
5
5
|
/**
|
|
6
6
|
* @param {Function} type - The constructor function/class
|
|
7
|
-
* @param {any[]} [args] - Arguments to pass to constructor
|
|
7
|
+
* @param {any[]|any} [args] - Arguments to pass to constructor (array or single value)
|
|
8
8
|
*/
|
|
9
|
-
constructor(type: Function, args?: any[]);
|
|
10
|
-
type
|
|
9
|
+
constructor(type: Function, args?: any[] | any);
|
|
10
|
+
/** @type {Function} */
|
|
11
|
+
Type: Function;
|
|
12
|
+
/** @type {any[]} */
|
|
11
13
|
arguments: any[];
|
|
12
14
|
}
|
|
@@ -65,6 +65,13 @@ export class ConfigRuntimeFactory {
|
|
|
65
65
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
|
|
66
66
|
*/
|
|
67
67
|
nodejs(configName?: string): RuntimeContext;
|
|
68
|
+
/**
|
|
69
|
+
* Creates RuntimeContext instance to interact with the Php runtime.
|
|
70
|
+
* @param {string} [configName="default"] - The name of the configuration to use (optional).
|
|
71
|
+
* @return {RuntimeContext} a RuntimeContext instance for the Php runtime
|
|
72
|
+
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/runtime-context)
|
|
73
|
+
*/
|
|
74
|
+
php(configName?: string): RuntimeContext;
|
|
68
75
|
/**
|
|
69
76
|
* Creates RuntimeContext instance to interact with the Python 2.7 runtime.
|
|
70
77
|
* @param {string} [configName="default"] - The name of the configuration to use (optional).
|
|
@@ -12,6 +12,7 @@ export type IConnectionData = import("../utils/connectionData/IConnectionData.js
|
|
|
12
12
|
* @class
|
|
13
13
|
*/
|
|
14
14
|
export class InvocationContext {
|
|
15
|
+
static _invocationContexts: Map<any, any>;
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
17
18
|
* @param {RuntimeNameType} runtimeName
|
|
@@ -20,22 +21,21 @@ export class InvocationContext {
|
|
|
20
21
|
* @param {boolean} isExecuted
|
|
21
22
|
*/
|
|
22
23
|
constructor(runtimeName: RuntimeNameType, connectionData: IConnectionData, command: Command, isExecuted?: boolean);
|
|
24
|
+
/**
|
|
25
|
+
* @returns {string} guid of this InvocationContext
|
|
26
|
+
*/
|
|
27
|
+
getGuid(): string;
|
|
23
28
|
/**
|
|
24
29
|
* @returns {Command|null}
|
|
25
30
|
*/
|
|
26
31
|
get_current_command(): Command | null;
|
|
27
32
|
/**
|
|
28
33
|
* Executes the current command.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Commands are becoming nested through each invocation of methods on Invocation Context.
|
|
32
|
-
* Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
|
|
33
|
-
* Developer can decide on any moment of the materialization for the context taking full control of the chunks of the expression being transferred and processed on target runtime.
|
|
34
|
-
* @returns {Promise<InvocationContext> | InvocationContext} the InvocationContext after executing the command.
|
|
35
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
|
|
34
|
+
* Returns the InvocationContext after executing the command.
|
|
35
|
+
* @returns {Promise<InvocationContext>}
|
|
36
36
|
* @method
|
|
37
37
|
*/
|
|
38
|
-
execute(): Promise<InvocationContext
|
|
38
|
+
execute(): Promise<InvocationContext>;
|
|
39
39
|
/**
|
|
40
40
|
* Invokes a static method on the target runtime.
|
|
41
41
|
* @param {string} methodName - The name of the method to invoke.
|
|
@@ -64,9 +64,10 @@ export class InvocationContext {
|
|
|
64
64
|
setStaticField(fieldName: string, value: any): InvocationContext;
|
|
65
65
|
/**
|
|
66
66
|
* Creates a new instance of a class in the target runtime.
|
|
67
|
+
* Adds the newly created context to the static invocation contexts map and
|
|
68
|
+
* includes the context GUID as the first argument of CreateClassInstance command payload.
|
|
67
69
|
* @param {...any} args - The arguments to pass to the class constructor
|
|
68
70
|
* @returns {InvocationContext} A new InvocationContext instance that wraps the command to create the instance.
|
|
69
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/calling-methods/creating-instance-and-calling-instance-methods)
|
|
70
71
|
* @method
|
|
71
72
|
*/
|
|
72
73
|
createInstance(...args: any[]): InvocationContext;
|
|
@@ -196,11 +197,11 @@ export class InvocationContext {
|
|
|
196
197
|
getInstanceMethodAsDelegate(methodName: string, ...args: any[]): InvocationContext;
|
|
197
198
|
/**
|
|
198
199
|
* Retrieves the type of the object from the target runtime.
|
|
199
|
-
* @returns {Promise<string>
|
|
200
|
+
* @returns {Promise<string>} The type of the object.
|
|
200
201
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
|
|
201
202
|
* @method
|
|
202
203
|
*/
|
|
203
|
-
getResultType(): Promise<string
|
|
204
|
+
getResultType(): Promise<string>;
|
|
204
205
|
/**
|
|
205
206
|
* Retrieves the name of the runtime where the command is executed.
|
|
206
207
|
* @returns {number} The name of the runtime.
|
|
@@ -210,6 +211,7 @@ export class InvocationContext {
|
|
|
210
211
|
getRuntimeName(): number;
|
|
211
212
|
/**
|
|
212
213
|
* Retrieves an array from the target runtime.
|
|
214
|
+
* @async
|
|
213
215
|
* @returns {Promise<any[]>}
|
|
214
216
|
* @method
|
|
215
217
|
*/
|
|
@@ -222,12 +224,12 @@ export class InvocationContext {
|
|
|
222
224
|
* @method
|
|
223
225
|
*/
|
|
224
226
|
getValue(): unknown;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Async iterator for InvocationContext arrays
|
|
229
|
+
* Use: for await (const item of invocationContext) { ... }
|
|
230
|
+
* @returns {AsyncGenerator<InvocationContext, void, unknown>}
|
|
231
|
+
*/
|
|
232
|
+
[Symbol.asyncIterator](): AsyncGenerator<InvocationContext, void, unknown>;
|
|
231
233
|
#private;
|
|
232
234
|
}
|
|
233
235
|
import { Command } from '../utils/Command.js';
|
|
@@ -77,7 +77,8 @@ import { WsConnectionData } from '../utils/connectionData/WsConnectionData.js';
|
|
|
77
77
|
import { CommandSerializer } from '../core/protocol/CommandSerializer.js';
|
|
78
78
|
import { CommandDeserializer } from '../core/protocol/CommandDeserializer.js';
|
|
79
79
|
import { ConfigPriority } from './configuration/ConfigPriority.js';
|
|
80
|
+
import { ComplexTypeResolver } from './tools/ComplexTypeResolver.js';
|
|
80
81
|
import { RuntimeFactory } from './RuntimeFactory.js';
|
|
81
82
|
import { ConfigRuntimeFactory } from './ConfigRuntimeFactory.js';
|
|
82
83
|
import { RuntimeContext } from './RuntimeContext.js';
|
|
83
|
-
export { TcpConnectionData, WsConnectionData, CommandSerializer, CommandDeserializer, ConfigPriority };
|
|
84
|
+
export { TcpConnectionData, WsConnectionData, CommandSerializer, CommandDeserializer, ConfigPriority, ComplexTypeResolver };
|
|
@@ -40,20 +40,21 @@ export class RuntimeContext {
|
|
|
40
40
|
* Each invocation triggers the creation of a new RuntimeContext instance wrapping the current command with a new parent command.
|
|
41
41
|
* The developer can decide at any moment of the materialization for the context, taking full control of the chunks of the expression being transferred and processed on the target runtime.
|
|
42
42
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
|
|
43
|
+
* @returns {Promise<void>}
|
|
43
44
|
* @method
|
|
44
45
|
*/
|
|
45
|
-
execute(): void
|
|
46
|
+
execute(): Promise<void>;
|
|
46
47
|
/**
|
|
47
48
|
* Adds a reference to a library. Javonet allows you to reference and use modules or packages written in various languages.
|
|
48
49
|
* This method allows you to use any library from all supported technologies. The necessary libraries need to be referenced.
|
|
49
50
|
* The argument is a relative or full path to the library. If the library has dependencies on other libraries, the latter needs to be added first.
|
|
50
51
|
* After referencing the library, any objects stored in this package can be used. Use static classes, create instances, call methods, use fields and properties, and much more.
|
|
51
52
|
* @param {string} libraryPath - The relative or full path to the library.
|
|
52
|
-
* @returns {RuntimeContext} RuntimeContext instance.
|
|
53
|
+
* @returns {Promise<RuntimeContext>} RuntimeContext instance.
|
|
53
54
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/getting-started/adding-references-to-libraries)
|
|
54
55
|
* @method
|
|
55
56
|
*/
|
|
56
|
-
loadLibrary(libraryPath: string): RuntimeContext
|
|
57
|
+
loadLibrary(libraryPath: string): Promise<RuntimeContext>;
|
|
57
58
|
/**
|
|
58
59
|
* Retrieves a reference to a specific type. The type can be a class, interface or enum. The type can be retrieved from any referenced library.
|
|
59
60
|
* @param {string} typeName - The full name of the type.
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
export class ConfigSourceResolver {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @param {import('./ConfigPriority.js').ConfigPriority} priority
|
|
4
|
+
* @param {string | any} configSource
|
|
5
|
+
*/
|
|
6
|
+
static addConfigs(priority: any, configSource: string | any): void;
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} configName
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
static getConfig(configName: string): any;
|
|
4
12
|
static clearConfigs(): void;
|
|
5
|
-
|
|
6
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} configSource
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
static _getConfigSourceAsString(configSource: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {import('./ConfigPriority.js').ConfigPriority} priority
|
|
20
|
+
* @param {string} configString
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
static _parseConfigsAndAddToCollection(priority: any, configString: string): void;
|
|
7
24
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export type RuntimeName = import("../../types.d.ts").RuntimeName;
|
|
2
|
-
/**
|
|
3
|
-
* @typedef {import('../../types.d.ts').RuntimeName} RuntimeName
|
|
4
|
-
*/
|
|
5
2
|
export class ComplexTypeResolver {
|
|
6
3
|
/**
|
|
7
4
|
* Resolve type from string name and optional module
|
|
@@ -10,6 +7,19 @@ export class ComplexTypeResolver {
|
|
|
10
7
|
* @returns {Function} The resolved type/constructor function
|
|
11
8
|
*/
|
|
12
9
|
static resolveType(typeName: string, moduleName?: string): Function;
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to extract the underlying element type from an array type string
|
|
12
|
+
* @param {string} type - The type string to parse (e.g., "MyType[]")
|
|
13
|
+
* @returns {string | null} Object indicating success and the element type
|
|
14
|
+
* @throws {Error} If the array element type is a primitive type
|
|
15
|
+
*/
|
|
16
|
+
static tryGetUnderlyingArrayType(type: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* @param {RuntimeName} runtimeName
|
|
19
|
+
* @param {string} resultType
|
|
20
|
+
* @returns {any}
|
|
21
|
+
*/
|
|
22
|
+
static tryGetTypeParsingFunction(runtimeName: RuntimeName, resultType: string): any;
|
|
13
23
|
/**
|
|
14
24
|
* Register a custom type mapping
|
|
15
25
|
* @param {string} resultType - The type name from the target runtime
|
|
@@ -20,9 +30,15 @@ export class ComplexTypeResolver {
|
|
|
20
30
|
/**
|
|
21
31
|
* Convert InvocationContext result to appropriate JavaScript type
|
|
22
32
|
* @param {InvocationContext} ic - The invocation context
|
|
23
|
-
* @returns {Promise<any>
|
|
33
|
+
* @returns {Promise<any>} The converted result
|
|
34
|
+
*/
|
|
35
|
+
convertResult(ic: InvocationContext): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} resultType
|
|
38
|
+
* @returns {ActivatorDetails | null}
|
|
24
39
|
*/
|
|
25
|
-
|
|
40
|
+
tryGetValueFromTypeMap(resultType: string): ActivatorDetails | null;
|
|
26
41
|
#private;
|
|
27
42
|
}
|
|
28
43
|
import { InvocationContext } from '../InvocationContext.js';
|
|
44
|
+
import { ActivatorDetails } from '../ActivatorDetails.js';
|
|
@@ -0,0 +1,201 @@
|
|
|
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 Primitives_exports = {};
|
|
20
|
+
__export(Primitives_exports, {
|
|
21
|
+
PrimitiveSet: () => PrimitiveSet
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Primitives_exports);
|
|
24
|
+
const PrimitiveSet = new Set(
|
|
25
|
+
[
|
|
26
|
+
// --- JavaScript / TypeScript ---
|
|
27
|
+
"string",
|
|
28
|
+
"number",
|
|
29
|
+
"boolean",
|
|
30
|
+
"bigint",
|
|
31
|
+
"symbol",
|
|
32
|
+
"undefined",
|
|
33
|
+
"null",
|
|
34
|
+
// --- .NET / C# ---
|
|
35
|
+
"bool",
|
|
36
|
+
"boolean",
|
|
37
|
+
"byte",
|
|
38
|
+
"sbyte",
|
|
39
|
+
"char",
|
|
40
|
+
"decimal",
|
|
41
|
+
"double",
|
|
42
|
+
"float",
|
|
43
|
+
"single",
|
|
44
|
+
"int",
|
|
45
|
+
"int32",
|
|
46
|
+
"uint",
|
|
47
|
+
"uint32",
|
|
48
|
+
"long",
|
|
49
|
+
"int64",
|
|
50
|
+
"ulong",
|
|
51
|
+
"uint64",
|
|
52
|
+
"short",
|
|
53
|
+
"int16",
|
|
54
|
+
"ushort",
|
|
55
|
+
"uint16",
|
|
56
|
+
"object",
|
|
57
|
+
"string",
|
|
58
|
+
"system.boolean",
|
|
59
|
+
"system.byte",
|
|
60
|
+
"system.sbyte",
|
|
61
|
+
"system.char",
|
|
62
|
+
"system.decimal",
|
|
63
|
+
"system.double",
|
|
64
|
+
"system.single",
|
|
65
|
+
"system.int",
|
|
66
|
+
"system.int32",
|
|
67
|
+
"system.uint",
|
|
68
|
+
"system.uint32",
|
|
69
|
+
"system.int64",
|
|
70
|
+
"system.uint64",
|
|
71
|
+
"system.int16",
|
|
72
|
+
"system.uint16",
|
|
73
|
+
"system.object",
|
|
74
|
+
"system.string",
|
|
75
|
+
// --- Java ---
|
|
76
|
+
"byte",
|
|
77
|
+
"short",
|
|
78
|
+
"int",
|
|
79
|
+
"long",
|
|
80
|
+
"float",
|
|
81
|
+
"double",
|
|
82
|
+
"char",
|
|
83
|
+
"boolean",
|
|
84
|
+
"java.lang.string",
|
|
85
|
+
// --- Python ---
|
|
86
|
+
"str",
|
|
87
|
+
"int",
|
|
88
|
+
"float",
|
|
89
|
+
"bool",
|
|
90
|
+
"bytes",
|
|
91
|
+
"bytearray",
|
|
92
|
+
// --- Go ---
|
|
93
|
+
"rune",
|
|
94
|
+
"byte",
|
|
95
|
+
"bool",
|
|
96
|
+
"string",
|
|
97
|
+
"int",
|
|
98
|
+
"int8",
|
|
99
|
+
"int16",
|
|
100
|
+
"int32",
|
|
101
|
+
"int64",
|
|
102
|
+
"uint",
|
|
103
|
+
"uint8",
|
|
104
|
+
"uint16",
|
|
105
|
+
"uint32",
|
|
106
|
+
"uint64",
|
|
107
|
+
"float32",
|
|
108
|
+
"float64",
|
|
109
|
+
// --- C / C++ ---
|
|
110
|
+
"char",
|
|
111
|
+
"short",
|
|
112
|
+
"int",
|
|
113
|
+
"long",
|
|
114
|
+
"float",
|
|
115
|
+
"double",
|
|
116
|
+
"signed char",
|
|
117
|
+
"unsigned char",
|
|
118
|
+
"unsigned short",
|
|
119
|
+
"unsigned int",
|
|
120
|
+
"unsigned long",
|
|
121
|
+
// --- Rust ---
|
|
122
|
+
"bool",
|
|
123
|
+
"u8",
|
|
124
|
+
"i8",
|
|
125
|
+
"u16",
|
|
126
|
+
"i16",
|
|
127
|
+
"u32",
|
|
128
|
+
"i32",
|
|
129
|
+
"u64",
|
|
130
|
+
"i64",
|
|
131
|
+
"f32",
|
|
132
|
+
"f64",
|
|
133
|
+
"usize",
|
|
134
|
+
"isize",
|
|
135
|
+
"str",
|
|
136
|
+
// --- Kotlin ---
|
|
137
|
+
"boolean",
|
|
138
|
+
"byte",
|
|
139
|
+
"short",
|
|
140
|
+
"int",
|
|
141
|
+
"long",
|
|
142
|
+
"float",
|
|
143
|
+
"double",
|
|
144
|
+
"char",
|
|
145
|
+
"string",
|
|
146
|
+
// --- Swift ---
|
|
147
|
+
"bool",
|
|
148
|
+
"int",
|
|
149
|
+
"uint",
|
|
150
|
+
"float",
|
|
151
|
+
"double",
|
|
152
|
+
"string",
|
|
153
|
+
"character",
|
|
154
|
+
// --- PHP ---
|
|
155
|
+
"int",
|
|
156
|
+
"integer",
|
|
157
|
+
"float",
|
|
158
|
+
"double",
|
|
159
|
+
"string",
|
|
160
|
+
"bool",
|
|
161
|
+
"boolean",
|
|
162
|
+
"mixed",
|
|
163
|
+
// --- Ruby ---
|
|
164
|
+
"string",
|
|
165
|
+
"integer",
|
|
166
|
+
"fixnum",
|
|
167
|
+
"float",
|
|
168
|
+
"symbol",
|
|
169
|
+
"boolean",
|
|
170
|
+
// --- Dart ---
|
|
171
|
+
"int",
|
|
172
|
+
"double",
|
|
173
|
+
"num",
|
|
174
|
+
"bool",
|
|
175
|
+
"string",
|
|
176
|
+
// --- Scala ---
|
|
177
|
+
"int",
|
|
178
|
+
"long",
|
|
179
|
+
"double",
|
|
180
|
+
"float",
|
|
181
|
+
"char",
|
|
182
|
+
"boolean",
|
|
183
|
+
"string",
|
|
184
|
+
// --- Haskell ---
|
|
185
|
+
"int",
|
|
186
|
+
"float",
|
|
187
|
+
"double",
|
|
188
|
+
"char",
|
|
189
|
+
"bool",
|
|
190
|
+
"integer",
|
|
191
|
+
// --- Generic aliases ---
|
|
192
|
+
"text",
|
|
193
|
+
"primitive",
|
|
194
|
+
"any",
|
|
195
|
+
"void"
|
|
196
|
+
].map((x) => x.toLowerCase())
|
|
197
|
+
);
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
PrimitiveSet
|
|
201
|
+
});
|
|
@@ -8,10 +8,28 @@ import { AbstractHandler } from './AbstractHandler.js'
|
|
|
8
8
|
class CreateClassInstanceHandler extends AbstractHandler {
|
|
9
9
|
requiredParametersCount = 1
|
|
10
10
|
|
|
11
|
+
// Add a simple invocation contexts store (Map GUID -> object)
|
|
12
|
+
static _invocationContexts = new Map()
|
|
13
|
+
|
|
14
|
+
static getOrCreateContextDictionary() {
|
|
15
|
+
// In a simple approach we keep a single map for the process.
|
|
16
|
+
return CreateClassInstanceHandler._invocationContexts
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
constructor() {
|
|
12
20
|
super()
|
|
13
21
|
}
|
|
14
22
|
|
|
23
|
+
// Helper to detect GUID in payload (standard format)
|
|
24
|
+
/**
|
|
25
|
+
* @param {{ toString: () => any; } | null} value
|
|
26
|
+
*/
|
|
27
|
+
static isGuid(value) {
|
|
28
|
+
if (value == null) return false
|
|
29
|
+
const s = value.toString()
|
|
30
|
+
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(s)
|
|
31
|
+
}
|
|
32
|
+
|
|
15
33
|
/**
|
|
16
34
|
* @param {Command} command
|
|
17
35
|
*/
|
|
@@ -20,8 +38,29 @@ class CreateClassInstanceHandler extends AbstractHandler {
|
|
|
20
38
|
if (command.payload.length < this.requiredParametersCount) {
|
|
21
39
|
throw new Error('Create Class Instance parameters mismatch')
|
|
22
40
|
}
|
|
41
|
+
|
|
23
42
|
let clazz = command.payload[0]
|
|
24
|
-
|
|
43
|
+
|
|
44
|
+
// Extract optional GUID and constructor arguments
|
|
45
|
+
let payloadLength = command.payload.length
|
|
46
|
+
let contextGuid = null
|
|
47
|
+
let constructorArguments = []
|
|
48
|
+
|
|
49
|
+
if (payloadLength > 1 && CreateClassInstanceHandler.isGuid(command.payload[1])) {
|
|
50
|
+
contextGuid = command.payload[1].toString()
|
|
51
|
+
if (payloadLength > 2) {
|
|
52
|
+
constructorArguments = command.payload.slice(2)
|
|
53
|
+
} else {
|
|
54
|
+
constructorArguments = []
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if (payloadLength > 1) {
|
|
58
|
+
constructorArguments = command.payload.slice(1)
|
|
59
|
+
} else {
|
|
60
|
+
constructorArguments = []
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
25
64
|
let instance = new clazz(...constructorArguments)
|
|
26
65
|
if (typeof instance === 'undefined') {
|
|
27
66
|
let methods = Object.getOwnPropertyNames(clazz).filter(function (property) {
|
|
@@ -33,6 +72,12 @@ class CreateClassInstanceHandler extends AbstractHandler {
|
|
|
33
72
|
})
|
|
34
73
|
throw new Error(message)
|
|
35
74
|
} else {
|
|
75
|
+
// If GUID provided, store instance in context dictionary
|
|
76
|
+
if (contextGuid) {
|
|
77
|
+
const contextDict = CreateClassInstanceHandler.getOrCreateContextDictionary()
|
|
78
|
+
// Overwrite or add entry
|
|
79
|
+
contextDict.set(contextGuid, instance)
|
|
80
|
+
}
|
|
36
81
|
return instance
|
|
37
82
|
}
|
|
38
83
|
} catch (error) {
|
|
@@ -135,19 +135,14 @@ class Handler {
|
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* @param {Command} command
|
|
138
|
+
* @returns {Promise<Command> | Command}
|
|
138
139
|
*/
|
|
139
140
|
handleCommand(command) {
|
|
140
141
|
try {
|
|
141
142
|
if (command.commandType === CommandType.RetrieveArray) {
|
|
142
143
|
/** @type {any} */
|
|
143
144
|
const responseArray = handlers[CommandType.Reference].handleCommand(command.payload[0])
|
|
144
|
-
|
|
145
|
-
return responseArray.then((resolvedResponseArray) => {
|
|
146
|
-
return Command.createArrayResponse(resolvedResponseArray, command.runtimeName)
|
|
147
|
-
})
|
|
148
|
-
} else {
|
|
149
|
-
return Command.createArrayResponse(responseArray, command.runtimeName)
|
|
150
|
-
}
|
|
145
|
+
return Command.createArrayResponse(responseArray, command.runtimeName)
|
|
151
146
|
}
|
|
152
147
|
/** @type {any} */
|
|
153
148
|
const response = handlers[command.commandType].handleCommand(command)
|
|
@@ -169,13 +164,43 @@ class Handler {
|
|
|
169
164
|
})
|
|
170
165
|
}
|
|
171
166
|
|
|
167
|
+
// Create base responseCommand (either primitive response or a reference)
|
|
168
|
+
let responseCommand
|
|
172
169
|
if (TypesHandler.isPrimitiveOrNullOrUndefined(response)) {
|
|
173
|
-
|
|
170
|
+
responseCommand = Command.createResponse(response, runtimeName)
|
|
174
171
|
} else {
|
|
175
172
|
let cache = ReferencesCache.getInstance()
|
|
176
173
|
let uuid = cache.cacheReference(response)
|
|
177
|
-
|
|
174
|
+
responseCommand = Command.createReference(uuid, runtimeName)
|
|
178
175
|
}
|
|
176
|
+
|
|
177
|
+
// If any invocation contexts were created during instance creation, attach UpdateInvocationContext commands
|
|
178
|
+
const invocationContexts = CreateClassInstanceHandler._invocationContexts
|
|
179
|
+
if (invocationContexts && typeof invocationContexts.size === 'number' && invocationContexts.size > 0) {
|
|
180
|
+
const refCache = ReferencesCache.getInstance()
|
|
181
|
+
for (const [contextKey, instance] of invocationContexts.entries()) {
|
|
182
|
+
const instanceGuid = refCache.cacheReference(instance)
|
|
183
|
+
const updateContextCommand = new Command(
|
|
184
|
+
runtimeName,
|
|
185
|
+
CommandType.UpdateInvocationContext,
|
|
186
|
+
[contextKey.toString(),
|
|
187
|
+
instanceGuid]
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
// Prefer using addArgToPayload if available, otherwise push into payload array
|
|
191
|
+
if (typeof responseCommand.addArgToPayload === 'function') {
|
|
192
|
+
responseCommand = responseCommand.addArgToPayload(updateContextCommand)
|
|
193
|
+
} else {
|
|
194
|
+
responseCommand.payload = responseCommand.payload || []
|
|
195
|
+
responseCommand.payload.push(updateContextCommand)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Clear contexts after attaching them to the response
|
|
200
|
+
invocationContexts.clear()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return responseCommand
|
|
179
204
|
}
|
|
180
205
|
}
|
|
181
206
|
|