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
|
@@ -25,10 +25,10 @@ var import_DelegatesCache = require("../core/delegatesCache/DelegatesCache.cjs")
|
|
|
25
25
|
var import_Interpreter = require("../core/interpreter/Interpreter.cjs");
|
|
26
26
|
var import_Command = require("../utils/Command.cjs");
|
|
27
27
|
var import_CommandType = require("../utils/CommandType.cjs");
|
|
28
|
-
var import_ConnectionType = require("../utils/ConnectionType.cjs");
|
|
29
28
|
var import_ExceptionThrower = require("../utils/exception/ExceptionThrower.cjs");
|
|
30
29
|
var import_RuntimeName = require("../utils/RuntimeName.cjs");
|
|
31
30
|
var import_TypesHandler = require("../utils/TypesHandler.cjs");
|
|
31
|
+
var import_uuid = require("uuid");
|
|
32
32
|
class InvocationContext {
|
|
33
33
|
/** @type {RuntimeNameType} */
|
|
34
34
|
#runtimeName;
|
|
@@ -36,12 +36,16 @@ class InvocationContext {
|
|
|
36
36
|
#connectionData;
|
|
37
37
|
/** @type {Command | null} */
|
|
38
38
|
#currentCommand = null;
|
|
39
|
-
/** @type {Command |
|
|
39
|
+
/** @type {Command | null} */
|
|
40
40
|
#responseCommand = null;
|
|
41
41
|
/** @type {boolean} */
|
|
42
42
|
#isExecuted = false;
|
|
43
43
|
/** @type {Interpreter | null} */
|
|
44
44
|
#interpreter = null;
|
|
45
|
+
/** @type {string | null} */
|
|
46
|
+
#guid = null;
|
|
47
|
+
// Static map holding contexts waiting for materialization (guid -> InvocationContext)
|
|
48
|
+
static _invocationContexts = /* @__PURE__ */ new Map();
|
|
45
49
|
/**
|
|
46
50
|
*
|
|
47
51
|
* @param {RuntimeNameType} runtimeName
|
|
@@ -56,6 +60,13 @@ class InvocationContext {
|
|
|
56
60
|
this.#responseCommand = null;
|
|
57
61
|
this.#isExecuted = isExecuted;
|
|
58
62
|
this.#interpreter = null;
|
|
63
|
+
this.#guid = (0, import_uuid.v4)();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @returns {string} guid of this InvocationContext
|
|
67
|
+
*/
|
|
68
|
+
getGuid() {
|
|
69
|
+
return this.#guid;
|
|
59
70
|
}
|
|
60
71
|
/**
|
|
61
72
|
* @param {Command} localCommand
|
|
@@ -84,68 +95,48 @@ class InvocationContext {
|
|
|
84
95
|
// this.execute();
|
|
85
96
|
// }
|
|
86
97
|
//}
|
|
87
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Async iterator for InvocationContext arrays
|
|
100
|
+
* Use: for await (const item of invocationContext) { ... }
|
|
101
|
+
* @returns {AsyncGenerator<InvocationContext, void, unknown>}
|
|
102
|
+
*/
|
|
103
|
+
async *[Symbol.asyncIterator]() {
|
|
88
104
|
if (this.#currentCommand?.commandType !== import_CommandType.CommandType.Reference) {
|
|
89
105
|
throw new Error("Object is not iterable");
|
|
90
106
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.getSize().execute()
|
|
96
|
-
);
|
|
97
|
-
if (sizeCtx instanceof Promise) {
|
|
98
|
-
sizeCtx.then((ctx) => {
|
|
99
|
-
arraySize = Number(ctx.getValue());
|
|
100
|
-
});
|
|
101
|
-
} else {
|
|
102
|
-
arraySize = Number(sizeCtx.getValue());
|
|
107
|
+
const sizeCtx = await this.getSize().execute();
|
|
108
|
+
const arraySize = Number(sizeCtx.getValue());
|
|
109
|
+
for (let position = 0; position < arraySize; position++) {
|
|
110
|
+
yield this.getIndex(position);
|
|
103
111
|
}
|
|
104
|
-
|
|
105
|
-
next: () => ({
|
|
106
|
-
value: this.getIndex(++position),
|
|
107
|
-
done: position >= arraySize
|
|
108
|
-
})
|
|
109
|
-
};
|
|
110
|
-
};
|
|
112
|
+
}
|
|
111
113
|
/**
|
|
112
114
|
* Executes the current command.
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* Commands are becoming nested through each invocation of methods on Invocation Context.
|
|
116
|
-
* Each invocation triggers the creation of new Invocation Context instance wrapping the current command with new parent command valid for invoked method.
|
|
117
|
-
* 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.
|
|
118
|
-
* @returns {Promise<InvocationContext> | InvocationContext} the InvocationContext after executing the command.
|
|
119
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
|
|
115
|
+
* Returns the InvocationContext after executing the command.
|
|
116
|
+
* @returns {Promise<InvocationContext>}
|
|
120
117
|
* @method
|
|
121
118
|
*/
|
|
122
|
-
execute() {
|
|
119
|
+
async execute() {
|
|
123
120
|
if (this.#currentCommand === null) {
|
|
124
121
|
throw new Error("currentCommand is undefined in Invocation Context execute method");
|
|
125
122
|
}
|
|
126
123
|
if (!this.#interpreter) {
|
|
127
124
|
this.#interpreter = new import_Interpreter.Interpreter();
|
|
128
125
|
}
|
|
129
|
-
this.#responseCommand = this.#interpreter.execute(this.#currentCommand, this.#connectionData);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return new InvocationContext(this.#runtimeName, this.#connectionData, resolvedResponse, true);
|
|
143
|
-
};
|
|
144
|
-
if (this.#responseCommand instanceof Promise) {
|
|
145
|
-
return this.#responseCommand.then(handleResponse);
|
|
146
|
-
} else {
|
|
147
|
-
return handleResponse(this.#responseCommand);
|
|
126
|
+
this.#responseCommand = await this.#interpreter.execute(this.#currentCommand, this.#connectionData);
|
|
127
|
+
if (!this.#responseCommand) {
|
|
128
|
+
throw new Error("responseCommand is undefined in Invocation Context execute method");
|
|
129
|
+
}
|
|
130
|
+
if (this.#responseCommand.commandType === import_CommandType.CommandType.Exception) {
|
|
131
|
+
throw import_ExceptionThrower.ExceptionThrower.throwException(this.#responseCommand);
|
|
132
|
+
}
|
|
133
|
+
this.#responseCommand = this.#processUpdateInvocationContextCommands(this.#responseCommand);
|
|
134
|
+
if (this.#responseCommand.commandType === import_CommandType.CommandType.CreateClassInstance) {
|
|
135
|
+
this.#currentCommand = this.#responseCommand;
|
|
136
|
+
this.#isExecuted = true;
|
|
137
|
+
return this;
|
|
148
138
|
}
|
|
139
|
+
return new InvocationContext(this.#runtimeName, this.#connectionData, this.#responseCommand, true);
|
|
149
140
|
}
|
|
150
141
|
/**
|
|
151
142
|
* Invokes a static method on the target runtime.
|
|
@@ -187,14 +178,24 @@ class InvocationContext {
|
|
|
187
178
|
}
|
|
188
179
|
/**
|
|
189
180
|
* Creates a new instance of a class in the target runtime.
|
|
181
|
+
* Adds the newly created context to the static invocation contexts map and
|
|
182
|
+
* includes the context GUID as the first argument of CreateClassInstance command payload.
|
|
190
183
|
* @param {...any} args - The arguments to pass to the class constructor
|
|
191
184
|
* @returns {InvocationContext} A new InvocationContext instance that wraps the command to create the instance.
|
|
192
|
-
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/calling-methods/creating-instance-and-calling-instance-methods)
|
|
193
185
|
* @method
|
|
194
186
|
*/
|
|
195
187
|
createInstance(...args) {
|
|
196
|
-
|
|
197
|
-
|
|
188
|
+
const dummyCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.CreateClassInstance, [
|
|
189
|
+
...args
|
|
190
|
+
]);
|
|
191
|
+
const createInstanceContext = new InvocationContext(this.#runtimeName, this.#connectionData, dummyCommand);
|
|
192
|
+
let localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.CreateClassInstance, [
|
|
193
|
+
createInstanceContext.getGuid(),
|
|
194
|
+
...args
|
|
195
|
+
]);
|
|
196
|
+
createInstanceContext.#currentCommand = this.#buildCommand(localCommand);
|
|
197
|
+
InvocationContext._invocationContexts.set(createInstanceContext.getGuid(), createInstanceContext);
|
|
198
|
+
return createInstanceContext;
|
|
198
199
|
}
|
|
199
200
|
/**
|
|
200
201
|
* Retrieves the value of an instance field from the target runtime.
|
|
@@ -382,21 +383,19 @@ class InvocationContext {
|
|
|
382
383
|
}
|
|
383
384
|
/**
|
|
384
385
|
* Retrieves the type of the object from the target runtime.
|
|
385
|
-
* @returns {Promise<string>
|
|
386
|
+
* @returns {Promise<string>} The type of the object.
|
|
386
387
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/type-handling/getting-object-type)
|
|
387
388
|
* @method
|
|
388
389
|
*/
|
|
389
|
-
getResultType() {
|
|
390
|
+
async getResultType() {
|
|
390
391
|
const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.GetResultType, []);
|
|
391
392
|
const invocationContext = new InvocationContext(
|
|
392
393
|
this.#runtimeName,
|
|
393
394
|
this.#connectionData,
|
|
394
395
|
this.#buildCommand(localCommand)
|
|
395
396
|
);
|
|
396
|
-
const execCtx = invocationContext.execute();
|
|
397
|
-
|
|
398
|
-
console.log(execCtx);
|
|
399
|
-
return execCtx instanceof Promise ? execCtx.then(extract) : extract(execCtx);
|
|
397
|
+
const execCtx = await invocationContext.execute();
|
|
398
|
+
return String(execCtx.getValue());
|
|
400
399
|
}
|
|
401
400
|
/**
|
|
402
401
|
* Retrieves the name of the runtime where the command is executed.
|
|
@@ -409,21 +408,33 @@ class InvocationContext {
|
|
|
409
408
|
}
|
|
410
409
|
/**
|
|
411
410
|
* Retrieves an array from the target runtime.
|
|
411
|
+
* @async
|
|
412
412
|
* @returns {Promise<any[]>}
|
|
413
413
|
* @method
|
|
414
414
|
*/
|
|
415
|
-
retrieveArray() {
|
|
415
|
+
async retrieveArray() {
|
|
416
416
|
const localCommand = new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.RetrieveArray, []);
|
|
417
417
|
const localInvCtx = new InvocationContext(
|
|
418
418
|
this.#runtimeName,
|
|
419
419
|
this.#connectionData,
|
|
420
420
|
this.#buildCommand(localCommand)
|
|
421
421
|
);
|
|
422
|
-
localInvCtx.execute();
|
|
423
|
-
const
|
|
424
|
-
return
|
|
422
|
+
await localInvCtx.execute();
|
|
423
|
+
const resolve = (item) => {
|
|
424
|
+
return item?.commandType === import_CommandType.CommandType.Reference ? new InvocationContext(
|
|
425
|
+
this.#runtimeName,
|
|
426
|
+
this.#connectionData,
|
|
427
|
+
item
|
|
428
|
+
) : item;
|
|
425
429
|
};
|
|
426
|
-
|
|
430
|
+
const respCommand = localInvCtx.#responseCommand;
|
|
431
|
+
if (!respCommand) {
|
|
432
|
+
return [];
|
|
433
|
+
}
|
|
434
|
+
if (respCommand.payload) {
|
|
435
|
+
return respCommand.payload.map((item) => resolve(item));
|
|
436
|
+
}
|
|
437
|
+
return respCommand.payload || [];
|
|
427
438
|
}
|
|
428
439
|
/**
|
|
429
440
|
* Returns the primitive value from the target runtime. This could be any primitive type in JavaScript,
|
|
@@ -465,9 +476,8 @@ class InvocationContext {
|
|
|
465
476
|
for (let i = 0; i < newArray.length; i++) {
|
|
466
477
|
newArray[i] = typeof Object;
|
|
467
478
|
}
|
|
468
|
-
const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs]
|
|
469
|
-
|
|
470
|
-
);
|
|
479
|
+
const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs];
|
|
480
|
+
args.push(...newArray);
|
|
471
481
|
return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.PassDelegate, args);
|
|
472
482
|
} else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
|
|
473
483
|
return new import_Command.Command(this.#runtimeName, import_CommandType.CommandType.Value, [payloadItem]);
|
|
@@ -477,6 +487,42 @@ class InvocationContext {
|
|
|
477
487
|
);
|
|
478
488
|
}
|
|
479
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Process UpdateInvocationContext commands in the provided responseCommand payload.
|
|
492
|
+
* For each UpdateInvocationContext command, set the referenced InvocationContext's currentCommand to a Reference command,
|
|
493
|
+
* remove that InvocationContext from the static map and remove UpdateInvocationContext items from response payload.
|
|
494
|
+
* @param {Command} responseCommand
|
|
495
|
+
* @returns {Command}
|
|
496
|
+
*/
|
|
497
|
+
#processUpdateInvocationContextCommands(responseCommand) {
|
|
498
|
+
if (!responseCommand?.payload?.length) {
|
|
499
|
+
return responseCommand;
|
|
500
|
+
}
|
|
501
|
+
const commandsToUpdate = responseCommand.payload.filter(
|
|
502
|
+
(item) => item instanceof import_Command.Command && item.commandType === import_CommandType.CommandType.UpdateInvocationContext
|
|
503
|
+
);
|
|
504
|
+
if (commandsToUpdate.length === 0) {
|
|
505
|
+
return responseCommand;
|
|
506
|
+
}
|
|
507
|
+
const updatedPayload = new Set(responseCommand.payload);
|
|
508
|
+
for (const cmd of commandsToUpdate) {
|
|
509
|
+
if (cmd.payload?.length >= 2) {
|
|
510
|
+
const contextGuid = String(cmd.payload[0]);
|
|
511
|
+
const instanceGuid = cmd.payload[1];
|
|
512
|
+
const invCtx = InvocationContext._invocationContexts.get(contextGuid);
|
|
513
|
+
if (invCtx) {
|
|
514
|
+
invCtx.#currentCommand = new import_Command.Command(invCtx.#runtimeName, import_CommandType.CommandType.Reference, [instanceGuid]);
|
|
515
|
+
InvocationContext._invocationContexts.delete(contextGuid);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
updatedPayload.delete(cmd);
|
|
519
|
+
}
|
|
520
|
+
return new import_Command.Command(
|
|
521
|
+
responseCommand.runtimeName,
|
|
522
|
+
responseCommand.commandType,
|
|
523
|
+
Array.from(updatedPayload)
|
|
524
|
+
);
|
|
525
|
+
}
|
|
480
526
|
}
|
|
481
527
|
// Annotate the CommonJS export names for ESM import in node:
|
|
482
528
|
0 && (module.exports = {
|
package/dist/sdk/Javonet.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var Javonet_exports = {};
|
|
|
20
20
|
__export(Javonet_exports, {
|
|
21
21
|
CommandDeserializer: () => import_CommandDeserializer.CommandDeserializer,
|
|
22
22
|
CommandSerializer: () => import_CommandSerializer.CommandSerializer,
|
|
23
|
+
ComplexTypeResolver: () => import_ComplexTypeResolver.ComplexTypeResolver,
|
|
23
24
|
ConfigPriority: () => import_ConfigPriority.ConfigPriority,
|
|
24
25
|
Javonet: () => Javonet,
|
|
25
26
|
TcpConnectionData: () => import_TcpConnectionData.TcpConnectionData,
|
|
@@ -39,6 +40,7 @@ var import_WsConnectionData = require("../utils/connectionData/WsConnectionData.
|
|
|
39
40
|
var import_UtilsConst = require("../utils/UtilsConst.cjs");
|
|
40
41
|
var import_ConfigSourceResolver = require("./configuration/ConfigSourceResolver.cjs");
|
|
41
42
|
var import_ConfigPriority = require("./configuration/ConfigPriority.cjs");
|
|
43
|
+
var import_ComplexTypeResolver = require("./tools/ComplexTypeResolver.cjs");
|
|
42
44
|
class Javonet {
|
|
43
45
|
/**
|
|
44
46
|
* Initializes Javonet using an in-memory channel on the same machine.
|
|
@@ -134,6 +136,7 @@ class Javonet {
|
|
|
134
136
|
0 && (module.exports = {
|
|
135
137
|
CommandDeserializer,
|
|
136
138
|
CommandSerializer,
|
|
139
|
+
ComplexTypeResolver,
|
|
137
140
|
ConfigPriority,
|
|
138
141
|
Javonet,
|
|
139
142
|
TcpConnectionData,
|
|
@@ -136,10 +136,11 @@ class RuntimeContext {
|
|
|
136
136
|
* Each invocation triggers the creation of a new RuntimeContext instance wrapping the current command with a new parent command.
|
|
137
137
|
* 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.
|
|
138
138
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/foundations/execute-method)
|
|
139
|
+
* @returns {Promise<void>}
|
|
139
140
|
* @method
|
|
140
141
|
*/
|
|
141
|
-
execute() {
|
|
142
|
-
this.#responseCommand = this.#interpreter?.execute(this.#currentCommand, this.connectionData);
|
|
142
|
+
async execute() {
|
|
143
|
+
this.#responseCommand = await this.#interpreter?.execute(this.#currentCommand, this.connectionData);
|
|
143
144
|
this.#currentCommand = null;
|
|
144
145
|
if (this.#responseCommand === void 0) {
|
|
145
146
|
throw new Error("responseCommand is undefined in Runtime Context execute method");
|
|
@@ -154,14 +155,14 @@ class RuntimeContext {
|
|
|
154
155
|
* 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.
|
|
155
156
|
* 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.
|
|
156
157
|
* @param {string} libraryPath - The relative or full path to the library.
|
|
157
|
-
* @returns {RuntimeContext} RuntimeContext instance.
|
|
158
|
+
* @returns {Promise<RuntimeContext>} RuntimeContext instance.
|
|
158
159
|
* @see [Javonet Guides](https://www.javonet.com/guides/v2/javascript/getting-started/adding-references-to-libraries)
|
|
159
160
|
* @method
|
|
160
161
|
*/
|
|
161
|
-
loadLibrary(libraryPath) {
|
|
162
|
+
async loadLibrary(libraryPath) {
|
|
162
163
|
let localCommand = new import_Command.Command(this.runtimeName, import_CommandType.CommandType.LoadLibrary, [libraryPath]);
|
|
163
164
|
this.#currentCommand = this.#buildCommand(localCommand);
|
|
164
|
-
this.execute();
|
|
165
|
+
await this.execute();
|
|
165
166
|
return this;
|
|
166
167
|
}
|
|
167
168
|
/**
|
|
@@ -296,9 +297,8 @@ class RuntimeContext {
|
|
|
296
297
|
for (let i = 0; i < newArray.length; i++) {
|
|
297
298
|
newArray[i] = "object";
|
|
298
299
|
}
|
|
299
|
-
const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs]
|
|
300
|
-
|
|
301
|
-
);
|
|
300
|
+
const args = [import_DelegatesCache.delegatesCacheInstance.addDelegate(payloadItem), import_RuntimeName.RuntimeName.Nodejs];
|
|
301
|
+
args.push(...newArray);
|
|
302
302
|
return new import_Command.Command(this.runtimeName, import_CommandType.CommandType.PassDelegate, args);
|
|
303
303
|
} else if (import_TypesHandler.TypesHandler.isPrimitiveOrNullOrUndefined(payloadItem)) {
|
|
304
304
|
return new import_Command.Command(this.runtimeName, import_CommandType.CommandType.Value, [payloadItem]);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,32 +15,39 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var ConfigSourceResolver_exports = {};
|
|
30
20
|
__export(ConfigSourceResolver_exports, {
|
|
31
21
|
ConfigSourceResolver: () => ConfigSourceResolver
|
|
32
22
|
});
|
|
33
23
|
module.exports = __toCommonJS(ConfigSourceResolver_exports);
|
|
34
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
35
|
-
var import_process = __toESM(require("process"), 1);
|
|
36
24
|
var import_ConfigsDictionary = require("./ConfigsDictionary.cjs");
|
|
37
25
|
var import_JsonConfigResolver = require("./configResolvers/JsonConfigResolver.cjs");
|
|
38
26
|
var import_YamlConfigResolver = require("./configResolvers/YamlConfigResolver.cjs");
|
|
39
27
|
var import_ConnectionStringConfigResolver = require("./configResolvers/ConnectionStringConfigResolver.cjs");
|
|
28
|
+
var import_Runtime = require("../../utils/Runtime.cjs");
|
|
29
|
+
const import_meta = {};
|
|
30
|
+
let fs = null;
|
|
31
|
+
let process = null;
|
|
32
|
+
const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
|
|
40
33
|
class ConfigSourceResolver {
|
|
34
|
+
/**
|
|
35
|
+
* @param {import('./ConfigPriority.js').ConfigPriority} priority
|
|
36
|
+
* @param {string | any} configSource
|
|
37
|
+
*/
|
|
41
38
|
static addConfigs(priority, configSource) {
|
|
42
39
|
console.log(`Adding config from source: ${configSource} with priority '${priority}'`);
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
if (configSource && typeof configSource === "object") {
|
|
41
|
+
import_JsonConfigResolver.JsonConfigResolver.addConfigs(priority, configSource);
|
|
42
|
+
} else {
|
|
43
|
+
const configString = ConfigSourceResolver._getConfigSourceAsString(configSource);
|
|
44
|
+
ConfigSourceResolver._parseConfigsAndAddToCollection(priority, configString);
|
|
45
|
+
}
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @param {string} configName
|
|
49
|
+
* @returns {*}
|
|
50
|
+
*/
|
|
46
51
|
static getConfig(configName) {
|
|
47
52
|
console.log(`Retrieving config ${configName}`);
|
|
48
53
|
return import_ConfigsDictionary.ConfigsDictionary.getConfig(configName);
|
|
@@ -50,19 +55,36 @@ class ConfigSourceResolver {
|
|
|
50
55
|
static clearConfigs() {
|
|
51
56
|
import_ConfigsDictionary.ConfigsDictionary.clearConfigs();
|
|
52
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} configSource
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
53
62
|
static _getConfigSourceAsString(configSource) {
|
|
54
63
|
if (!configSource || configSource.trim() === "") {
|
|
55
64
|
throw new Error("Config source cannot be null or whitespace.");
|
|
56
65
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
if ((0, import_Runtime.isNodejsRuntime)()) {
|
|
67
|
+
if (!process) {
|
|
68
|
+
process = requireDynamic("process");
|
|
69
|
+
}
|
|
70
|
+
if (!fs) {
|
|
71
|
+
fs = requireDynamic("fs");
|
|
72
|
+
}
|
|
73
|
+
const envValue = process?.env[configSource];
|
|
74
|
+
if (envValue && envValue.trim() !== "") {
|
|
75
|
+
configSource = envValue;
|
|
76
|
+
}
|
|
77
|
+
if (fs?.existsSync(configSource) && fs?.statSync(configSource).isFile()) {
|
|
78
|
+
configSource = fs.readFileSync(configSource, { encoding: "utf-8" });
|
|
79
|
+
}
|
|
63
80
|
}
|
|
64
81
|
return configSource.trim();
|
|
65
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @param {import('./ConfigPriority.js').ConfigPriority} priority
|
|
85
|
+
* @param {string} configString
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
66
88
|
static _parseConfigsAndAddToCollection(priority, configString) {
|
|
67
89
|
try {
|
|
68
90
|
const jsonObject = JSON.parse(configString);
|
|
@@ -78,7 +100,7 @@ class ConfigSourceResolver {
|
|
|
78
100
|
import_YamlConfigResolver.YamlConfigResolver.addConfigs(priority, configString);
|
|
79
101
|
return;
|
|
80
102
|
} catch (ex) {
|
|
81
|
-
if (ex
|
|
103
|
+
if (ex?.name === "SyntaxError") {
|
|
82
104
|
} else {
|
|
83
105
|
console.log("Failed to parse config source as YAML: " + ex);
|
|
84
106
|
}
|
|
@@ -21,8 +21,10 @@ __export(ComplexTypeResolver_exports, {
|
|
|
21
21
|
ComplexTypeResolver: () => ComplexTypeResolver
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ComplexTypeResolver_exports);
|
|
24
|
+
var import_Primitives = require("../../utils/Primitives.cjs");
|
|
24
25
|
var import_Runtime = require("../../utils/Runtime.cjs");
|
|
25
26
|
var import_RuntimeName = require("../../utils/RuntimeName.cjs");
|
|
27
|
+
var import_Activator = require("../Activator.cjs");
|
|
26
28
|
var import_ActivatorDetails = require("../ActivatorDetails.cjs");
|
|
27
29
|
var import_InvocationContext = require("../InvocationContext.cjs");
|
|
28
30
|
var import_JavaTypeParsingFunctions = require("./typeParsingFunctions/JavaTypeParsingFunctions.cjs");
|
|
@@ -31,17 +33,19 @@ var import_NodejsTypeParsingFunctions = require("./typeParsingFunctions/NodejsTy
|
|
|
31
33
|
var import_PythonTypeParsingFunctions = require("./typeParsingFunctions/PythonTypeParsingFunctions.cjs");
|
|
32
34
|
const import_meta = {};
|
|
33
35
|
const dynamicImport = (0, import_Runtime.getRequire)(import_meta.url);
|
|
36
|
+
const typeParsingFunctions = /* @__PURE__ */ new Map([
|
|
37
|
+
[import_RuntimeName.RuntimeName.Netcore, import_NetcoreTypeParsingFunctions.NetcoreTypeParsingFunctions],
|
|
38
|
+
[import_RuntimeName.RuntimeName.Jvm, import_JavaTypeParsingFunctions.JavaTypeParsingFunctions],
|
|
39
|
+
[import_RuntimeName.RuntimeName.Nodejs, import_NodejsTypeParsingFunctions.NodejsTypeParsingFunctions],
|
|
40
|
+
[import_RuntimeName.RuntimeName.Python, import_PythonTypeParsingFunctions.PythonTypeParsingFunctions],
|
|
41
|
+
[import_RuntimeName.RuntimeName.Python27, import_PythonTypeParsingFunctions.PythonTypeParsingFunctions]
|
|
42
|
+
]);
|
|
34
43
|
class ComplexTypeResolver {
|
|
35
44
|
/** @type {Map<string, ActivatorDetails>} */
|
|
36
|
-
#typeMap
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
[import_RuntimeName.RuntimeName.Jvm, import_JavaTypeParsingFunctions.JavaTypeParsingFunctions],
|
|
41
|
-
[import_RuntimeName.RuntimeName.Nodejs, import_NodejsTypeParsingFunctions.NodejsTypeParsingFunctions],
|
|
42
|
-
[import_RuntimeName.RuntimeName.Python, import_PythonTypeParsingFunctions.PythonTypeParsingFunctions],
|
|
43
|
-
[import_RuntimeName.RuntimeName.Python27, import_PythonTypeParsingFunctions.PythonTypeParsingFunctions]
|
|
44
|
-
]);
|
|
45
|
+
#typeMap;
|
|
46
|
+
constructor() {
|
|
47
|
+
this.#typeMap = /* @__PURE__ */ new Map();
|
|
48
|
+
}
|
|
45
49
|
/**
|
|
46
50
|
* Register a custom type mapping
|
|
47
51
|
* @param {string} resultType - The type name from the target runtime
|
|
@@ -56,38 +60,40 @@ class ComplexTypeResolver {
|
|
|
56
60
|
/**
|
|
57
61
|
* Convert InvocationContext result to appropriate JavaScript type
|
|
58
62
|
* @param {InvocationContext} ic - The invocation context
|
|
59
|
-
* @returns {Promise<any>
|
|
63
|
+
* @returns {Promise<any>} The converted result
|
|
60
64
|
*/
|
|
61
|
-
convertResult(ic) {
|
|
65
|
+
async convertResult(ic) {
|
|
62
66
|
const runtimeName = ic.getRuntimeName();
|
|
63
|
-
const resultType = ic.getResultType();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let parsingFunc = null;
|
|
67
|
-
if (resultType instanceof Promise) {
|
|
68
|
-
parsingFunc = resultType.then((result) => {
|
|
69
|
-
parsingFunc = runtimeDict.get(result);
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
parsingFunc = runtimeDict.get(resultType);
|
|
73
|
-
}
|
|
74
|
-
if (parsingFunc) {
|
|
75
|
-
return parsingFunc(ic);
|
|
76
|
-
}
|
|
67
|
+
const resultType = await ic.getResultType();
|
|
68
|
+
if (!resultType) {
|
|
69
|
+
throw new Error("resultType is not valid");
|
|
77
70
|
}
|
|
78
|
-
let
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
let underlyingType = ComplexTypeResolver.tryGetUnderlyingArrayType(resultType);
|
|
72
|
+
if (underlyingType !== null) {
|
|
73
|
+
const { Type } = (
|
|
74
|
+
/** @type {ActivatorDetails} */
|
|
75
|
+
this.#typeMap.get(underlyingType)
|
|
76
|
+
);
|
|
77
|
+
const complexTypesArray = await ic.retrieveArray();
|
|
78
|
+
return complexTypesArray.map((item) => import_Activator.Activator.createInstance(Type, item));
|
|
85
79
|
}
|
|
80
|
+
const parsingFunction = ComplexTypeResolver.tryGetTypeParsingFunction(runtimeName, resultType);
|
|
81
|
+
if (parsingFunction) {
|
|
82
|
+
return parsingFunction(ic);
|
|
83
|
+
}
|
|
84
|
+
const activatorDetails = this.tryGetValueFromTypeMap(resultType);
|
|
86
85
|
if (!activatorDetails) {
|
|
87
86
|
throw new Error(`No type registered for key '${resultType}'.`);
|
|
88
87
|
}
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
if (runtimeName === import_RuntimeName.RuntimeName.Nodejs) {
|
|
89
|
+
const value = await ic.getValue();
|
|
90
|
+
if (value) {
|
|
91
|
+
if (value instanceof activatorDetails.Type) {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return import_Activator.Activator.createInstance(activatorDetails.Type, activatorDetails.arguments ?? null);
|
|
91
97
|
}
|
|
92
98
|
/**
|
|
93
99
|
* Resolve type from string name and optional module
|
|
@@ -121,6 +127,50 @@ class ComplexTypeResolver {
|
|
|
121
127
|
}
|
|
122
128
|
return typeObj;
|
|
123
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Attempts to extract the underlying element type from an array type string
|
|
132
|
+
* @param {string} type - The type string to parse (e.g., "MyType[]")
|
|
133
|
+
* @returns {string | null} Object indicating success and the element type
|
|
134
|
+
* @throws {Error} If the array element type is a primitive type
|
|
135
|
+
*/
|
|
136
|
+
static tryGetUnderlyingArrayType(type) {
|
|
137
|
+
if (typeof type !== "string" || !type.includes("[")) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
let trimmedType = type.trim();
|
|
141
|
+
if (!trimmedType) return null;
|
|
142
|
+
const commaIndex = trimmedType.indexOf(",");
|
|
143
|
+
if (commaIndex > 0) {
|
|
144
|
+
trimmedType = trimmedType.substring(0, commaIndex).trim();
|
|
145
|
+
}
|
|
146
|
+
const bracketIndex = trimmedType.indexOf("[");
|
|
147
|
+
if (bracketIndex > 0) {
|
|
148
|
+
trimmedType = trimmedType.substring(0, bracketIndex).trim();
|
|
149
|
+
}
|
|
150
|
+
if (import_Primitives.PrimitiveSet.has(trimmedType)) {
|
|
151
|
+
throw new Error("Primitive array element types are not supported.");
|
|
152
|
+
}
|
|
153
|
+
return trimmedType;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @param {RuntimeName} runtimeName
|
|
157
|
+
* @param {string} resultType
|
|
158
|
+
* @returns {any}
|
|
159
|
+
*/
|
|
160
|
+
static tryGetTypeParsingFunction(runtimeName, resultType) {
|
|
161
|
+
const runtimeDict = typeParsingFunctions.get(runtimeName);
|
|
162
|
+
return runtimeDict ? runtimeDict.get(resultType) ?? null : null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param {string} resultType
|
|
166
|
+
* @returns {ActivatorDetails | null}
|
|
167
|
+
*/
|
|
168
|
+
tryGetValueFromTypeMap(resultType) {
|
|
169
|
+
if (!resultType) {
|
|
170
|
+
throw new Error("resultType is not valid");
|
|
171
|
+
}
|
|
172
|
+
return this.#typeMap.get(resultType) ?? null;
|
|
173
|
+
}
|
|
124
174
|
}
|
|
125
175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
126
176
|
0 && (module.exports = {
|
|
@@ -3,6 +3,14 @@ export type Command = import("../../utils/Command.js").Command;
|
|
|
3
3
|
* @typedef {import('../../utils/Command.js').Command} Command
|
|
4
4
|
*/
|
|
5
5
|
export class CreateClassInstanceHandler extends AbstractHandler {
|
|
6
|
+
static _invocationContexts: Map<any, any>;
|
|
7
|
+
static getOrCreateContextDictionary(): Map<any, any>;
|
|
8
|
+
/**
|
|
9
|
+
* @param {{ toString: () => any; } | null} value
|
|
10
|
+
*/
|
|
11
|
+
static isGuid(value: {
|
|
12
|
+
toString: () => any;
|
|
13
|
+
} | null): boolean;
|
|
6
14
|
requiredParametersCount: number;
|
|
7
15
|
/**
|
|
8
16
|
* @param {Command} command
|
|
@@ -7,8 +7,9 @@ export class Handler {
|
|
|
7
7
|
interpreter: import("../interpreter/Interpreter.js").Interpreter;
|
|
8
8
|
/**
|
|
9
9
|
* @param {Command} command
|
|
10
|
+
* @returns {Promise<Command> | Command}
|
|
10
11
|
*/
|
|
11
|
-
handleCommand(command: Command): Command |
|
|
12
|
+
handleCommand(command: Command): Promise<Command> | Command;
|
|
12
13
|
/**
|
|
13
14
|
* @param {any} response
|
|
14
15
|
* @param {RuntimeName} runtimeName
|
|
@@ -68,9 +68,9 @@ export class PassDelegateHandler extends AbstractHandler {
|
|
|
68
68
|
/**
|
|
69
69
|
* Creates a method call to execute the command.
|
|
70
70
|
* @param {Command} command - The command object.
|
|
71
|
-
* @returns {any} The response object.
|
|
71
|
+
* @returns {Promise<any>} The response object.
|
|
72
72
|
*/
|
|
73
|
-
createExecuteCall(command: Command): any
|
|
73
|
+
createExecuteCall(command: Command): Promise<any>;
|
|
74
74
|
/**
|
|
75
75
|
* Retrieves the response payload from the execution call.
|
|
76
76
|
* @param {Object<string, any>} executeCall - Object containing the execution call.
|