@comake/skl-js-engine 1.5.2 → 1.5.4
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/package.json +1 -1
- package/src/SklEngine.ts +8 -1
- package/src/util/TripleUtil.ts +22 -2
- package/dist/JsExecutor/PermissionBuilder.d.ts +0 -14
- package/dist/JsExecutor/PermissionBuilder.d.ts.map +0 -1
- package/dist/JsExecutor/PermissionBuilder.js +0 -58
- package/dist/JsExecutor/PermissionBuilder.js.map +0 -1
- package/dist/JsExecutor/constants.d.ts +0 -27
- package/dist/JsExecutor/constants.d.ts.map +0 -1
- package/dist/JsExecutor/constants.js +0 -30
- package/dist/JsExecutor/constants.js.map +0 -1
- package/dist/JsExecutor/denoUtils.d.ts +0 -10
- package/dist/JsExecutor/denoUtils.d.ts.map +0 -1
- package/dist/JsExecutor/denoUtils.js +0 -24
- package/dist/JsExecutor/denoUtils.js.map +0 -1
- package/dist/JsExecutor/errors.d.ts +0 -40
- package/dist/JsExecutor/errors.d.ts.map +0 -1
- package/dist/JsExecutor/errors.js +0 -67
- package/dist/JsExecutor/errors.js.map +0 -1
- package/dist/JsExecutor/examples/basic/index.d.ts +0 -1
- package/dist/JsExecutor/examples/basic/index.d.ts.map +0 -1
- package/dist/JsExecutor/examples/basic/index.js +0 -46
- package/dist/JsExecutor/examples/basic/index.js.map +0 -1
- package/dist/JsExecutor/examples/basic/process.d.ts +0 -1
- package/dist/JsExecutor/examples/basic/process.d.ts.map +0 -1
- package/dist/JsExecutor/examples/basic/process.js +0 -34
- package/dist/JsExecutor/examples/basic/process.js.map +0 -1
- package/dist/JsExecutor/examples/jsExecutor/index.d.ts +0 -2
- package/dist/JsExecutor/examples/jsExecutor/index.d.ts.map +0 -1
- package/dist/JsExecutor/examples/jsExecutor/index.js +0 -47
- package/dist/JsExecutor/examples/jsExecutor/index.js.map +0 -1
- package/dist/JsExecutor/examples/jsExecutor/process.d.ts +0 -2
- package/dist/JsExecutor/examples/jsExecutor/process.d.ts.map +0 -1
- package/dist/JsExecutor/examples/jsExecutor/process.js +0 -58
- package/dist/JsExecutor/examples/jsExecutor/process.js.map +0 -1
- package/dist/JsExecutor/index.d.ts +0 -7
- package/dist/JsExecutor/index.d.ts.map +0 -1
- package/dist/JsExecutor/index.js +0 -36
- package/dist/JsExecutor/index.js.map +0 -1
- package/dist/JsExecutor/jsExecutor.d.ts +0 -68
- package/dist/JsExecutor/jsExecutor.d.ts.map +0 -1
- package/dist/JsExecutor/jsExecutor.js +0 -171
- package/dist/JsExecutor/jsExecutor.js.map +0 -1
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.d.ts +0 -165
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.d.ts.map +0 -1
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.js +0 -335
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.js.map +0 -1
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.d.ts +0 -125
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.d.ts.map +0 -1
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.js +0 -391
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.js.map +0 -1
- package/dist/JsExecutor/jsonRpc/index.d.ts +0 -4
- package/dist/JsExecutor/jsonRpc/index.d.ts.map +0 -1
- package/dist/JsExecutor/jsonRpc/index.js +0 -23
- package/dist/JsExecutor/jsonRpc/index.js.map +0 -1
- package/dist/JsExecutor/jsonRpc/types.d.ts +0 -193
- package/dist/JsExecutor/jsonRpc/types.d.ts.map +0 -1
- package/dist/JsExecutor/jsonRpc/types.js +0 -37
- package/dist/JsExecutor/jsonRpc/types.js.map +0 -1
- package/dist/JsExecutor/transport/Transport.d.ts +0 -74
- package/dist/JsExecutor/transport/Transport.d.ts.map +0 -1
- package/dist/JsExecutor/transport/Transport.js +0 -14
- package/dist/JsExecutor/transport/Transport.js.map +0 -1
- package/dist/JsExecutor/transport/base/BaseTransport.d.ts +0 -51
- package/dist/JsExecutor/transport/base/BaseTransport.d.ts.map +0 -1
- package/dist/JsExecutor/transport/base/BaseTransport.js +0 -68
- package/dist/JsExecutor/transport/base/BaseTransport.js.map +0 -1
- package/dist/JsExecutor/transport/index.d.ts +0 -13
- package/dist/JsExecutor/transport/index.d.ts.map +0 -1
- package/dist/JsExecutor/transport/index.js +0 -36
- package/dist/JsExecutor/transport/index.js.map +0 -1
- package/dist/JsExecutor/transport/process/ProcessManager.d.ts +0 -96
- package/dist/JsExecutor/transport/process/ProcessManager.d.ts.map +0 -1
- package/dist/JsExecutor/transport/process/ProcessManager.js +0 -219
- package/dist/JsExecutor/transport/process/ProcessManager.js.map +0 -1
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.d.ts +0 -87
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.d.ts.map +0 -1
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.js +0 -219
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.js.map +0 -1
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.d.ts +0 -81
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.d.ts.map +0 -1
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.js +0 -259
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.js.map +0 -1
- package/dist/JsExecutor/transport/utils/MessageUtils.d.ts +0 -68
- package/dist/JsExecutor/transport/utils/MessageUtils.d.ts.map +0 -1
- package/dist/JsExecutor/transport/utils/MessageUtils.js +0 -135
- package/dist/JsExecutor/transport/utils/MessageUtils.js.map +0 -1
- package/dist/JsExecutor/transport/utils/PollingUtils.d.ts +0 -53
- package/dist/JsExecutor/transport/utils/PollingUtils.d.ts.map +0 -1
- package/dist/JsExecutor/transport/utils/PollingUtils.js +0 -92
- package/dist/JsExecutor/transport/utils/PollingUtils.js.map +0 -1
- package/dist/JsExecutor/types.d.ts +0 -113
- package/dist/JsExecutor/types.d.ts.map +0 -1
- package/dist/JsExecutor/types.js +0 -3
- package/dist/JsExecutor/types.js.map +0 -1
- package/dist/SklEngine.d.ts +0 -132
- package/dist/SklEngine.d.ts.map +0 -1
- package/dist/SklEngine.js +0 -1501
- package/dist/SklEngine.js.map +0 -1
- package/dist/SklEngineOptions.d.ts +0 -58
- package/dist/SklEngineOptions.d.ts.map +0 -1
- package/dist/SklEngineOptions.js +0 -3
- package/dist/SklEngineOptions.js.map +0 -1
- package/dist/constants.d.ts +0 -96
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -103
- package/dist/constants.js.map +0 -1
- package/dist/customCapabilities.d.ts +0 -22
- package/dist/customCapabilities.d.ts.map +0 -1
- package/dist/customCapabilities.js +0 -45
- package/dist/customCapabilities.js.map +0 -1
- package/dist/examples/customCapabilitiesExample.d.ts +0 -2
- package/dist/examples/customCapabilitiesExample.d.ts.map +0 -1
- package/dist/examples/customCapabilitiesExample.js +0 -59
- package/dist/examples/customCapabilitiesExample.js.map +0 -1
- package/dist/executor.js +0 -216
- package/dist/hooks/globalHooks.d.ts +0 -50
- package/dist/hooks/globalHooks.d.ts.map +0 -1
- package/dist/hooks/globalHooks.js +0 -164
- package/dist/hooks/globalHooks.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -9
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -3
- package/dist/hooks/types.js.map +0 -1
- package/dist/index.d.ts +0 -41
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -68
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -35
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -119
- package/dist/logger.js.map +0 -1
- package/dist/mapping/Mapper.d.ts +0 -13
- package/dist/mapping/Mapper.d.ts.map +0 -1
- package/dist/mapping/Mapper.js +0 -64
- package/dist/mapping/Mapper.js.map +0 -1
- package/dist/storage/FindOperator.d.ts +0 -19
- package/dist/storage/FindOperator.d.ts.map +0 -1
- package/dist/storage/FindOperator.js +0 -23
- package/dist/storage/FindOperator.js.map +0 -1
- package/dist/storage/FindOptionsTypes.d.ts +0 -79
- package/dist/storage/FindOptionsTypes.d.ts.map +0 -1
- package/dist/storage/FindOptionsTypes.js +0 -3
- package/dist/storage/FindOptionsTypes.js.map +0 -1
- package/dist/storage/GroupOptionTypes.d.ts +0 -29
- package/dist/storage/GroupOptionTypes.d.ts.map +0 -1
- package/dist/storage/GroupOptionTypes.js +0 -3
- package/dist/storage/GroupOptionTypes.js.map +0 -1
- package/dist/storage/operator/And.d.ts +0 -4
- package/dist/storage/operator/And.d.ts.map +0 -1
- package/dist/storage/operator/And.js +0 -13
- package/dist/storage/operator/And.js.map +0 -1
- package/dist/storage/operator/Contains.d.ts +0 -3
- package/dist/storage/operator/Contains.d.ts.map +0 -1
- package/dist/storage/operator/Contains.js +0 -13
- package/dist/storage/operator/Contains.js.map +0 -1
- package/dist/storage/operator/Equal.d.ts +0 -5
- package/dist/storage/operator/Equal.d.ts.map +0 -1
- package/dist/storage/operator/Equal.js +0 -13
- package/dist/storage/operator/Equal.js.map +0 -1
- package/dist/storage/operator/Exists.d.ts +0 -3
- package/dist/storage/operator/Exists.d.ts.map +0 -1
- package/dist/storage/operator/Exists.js +0 -10
- package/dist/storage/operator/Exists.js.map +0 -1
- package/dist/storage/operator/GreaterThan.d.ts +0 -4
- package/dist/storage/operator/GreaterThan.d.ts.map +0 -1
- package/dist/storage/operator/GreaterThan.js +0 -13
- package/dist/storage/operator/GreaterThan.js.map +0 -1
- package/dist/storage/operator/GreaterThanOrEqual.d.ts +0 -4
- package/dist/storage/operator/GreaterThanOrEqual.d.ts.map +0 -1
- package/dist/storage/operator/GreaterThanOrEqual.js +0 -13
- package/dist/storage/operator/GreaterThanOrEqual.js.map +0 -1
- package/dist/storage/operator/In.d.ts +0 -4
- package/dist/storage/operator/In.d.ts.map +0 -1
- package/dist/storage/operator/In.js +0 -13
- package/dist/storage/operator/In.js.map +0 -1
- package/dist/storage/operator/Inverse.d.ts +0 -3
- package/dist/storage/operator/Inverse.d.ts.map +0 -1
- package/dist/storage/operator/Inverse.js +0 -13
- package/dist/storage/operator/Inverse.js.map +0 -1
- package/dist/storage/operator/InversePath.d.ts +0 -7
- package/dist/storage/operator/InversePath.d.ts.map +0 -1
- package/dist/storage/operator/InversePath.js +0 -13
- package/dist/storage/operator/InversePath.js.map +0 -1
- package/dist/storage/operator/InverseRelation.d.ts +0 -9
- package/dist/storage/operator/InverseRelation.d.ts.map +0 -1
- package/dist/storage/operator/InverseRelation.js +0 -13
- package/dist/storage/operator/InverseRelation.js.map +0 -1
- package/dist/storage/operator/InverseRelationOrder.d.ts +0 -8
- package/dist/storage/operator/InverseRelationOrder.d.ts.map +0 -1
- package/dist/storage/operator/InverseRelationOrder.js +0 -13
- package/dist/storage/operator/InverseRelationOrder.js.map +0 -1
- package/dist/storage/operator/LessThan.d.ts +0 -4
- package/dist/storage/operator/LessThan.d.ts.map +0 -1
- package/dist/storage/operator/LessThan.js +0 -13
- package/dist/storage/operator/LessThan.js.map +0 -1
- package/dist/storage/operator/LessThanOrEqual.d.ts +0 -4
- package/dist/storage/operator/LessThanOrEqual.d.ts.map +0 -1
- package/dist/storage/operator/LessThanOrEqual.js +0 -13
- package/dist/storage/operator/LessThanOrEqual.js.map +0 -1
- package/dist/storage/operator/Not.d.ts +0 -3
- package/dist/storage/operator/Not.d.ts.map +0 -1
- package/dist/storage/operator/Not.js +0 -13
- package/dist/storage/operator/Not.js.map +0 -1
- package/dist/storage/operator/OneOrMorePath.d.ts +0 -7
- package/dist/storage/operator/OneOrMorePath.d.ts.map +0 -1
- package/dist/storage/operator/OneOrMorePath.js +0 -13
- package/dist/storage/operator/OneOrMorePath.js.map +0 -1
- package/dist/storage/operator/Or.d.ts +0 -4
- package/dist/storage/operator/Or.d.ts.map +0 -1
- package/dist/storage/operator/Or.js +0 -13
- package/dist/storage/operator/Or.js.map +0 -1
- package/dist/storage/operator/Sequence.d.ts +0 -3
- package/dist/storage/operator/Sequence.d.ts.map +0 -1
- package/dist/storage/operator/Sequence.js +0 -13
- package/dist/storage/operator/Sequence.js.map +0 -1
- package/dist/storage/operator/SequencePath.d.ts +0 -7
- package/dist/storage/operator/SequencePath.d.ts.map +0 -1
- package/dist/storage/operator/SequencePath.js +0 -13
- package/dist/storage/operator/SequencePath.js.map +0 -1
- package/dist/storage/operator/ZeroOrMorePath.d.ts +0 -7
- package/dist/storage/operator/ZeroOrMorePath.d.ts.map +0 -1
- package/dist/storage/operator/ZeroOrMorePath.js +0 -13
- package/dist/storage/operator/ZeroOrMorePath.js.map +0 -1
- package/dist/storage/query-adapter/QueryAdapter.d.ts +0 -99
- package/dist/storage/query-adapter/QueryAdapter.d.ts.map +0 -1
- package/dist/storage/query-adapter/QueryAdapter.js +0 -3
- package/dist/storage/query-adapter/QueryAdapter.js.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapter.d.ts +0 -40
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapter.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapter.js +0 -315
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapter.js.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapterOptions.d.ts +0 -34
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapterOptions.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapterOptions.js +0 -3
- package/dist/storage/query-adapter/sparql/SparqlQueryAdapterOptions.js.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlQueryBuilder.d.ts +0 -104
- package/dist/storage/query-adapter/sparql/SparqlQueryBuilder.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlQueryBuilder.js +0 -1210
- package/dist/storage/query-adapter/sparql/SparqlQueryBuilder.js.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlUpdateBuilder.d.ts +0 -41
- package/dist/storage/query-adapter/sparql/SparqlUpdateBuilder.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/SparqlUpdateBuilder.js +0 -305
- package/dist/storage/query-adapter/sparql/SparqlUpdateBuilder.js.map +0 -1
- package/dist/storage/query-adapter/sparql/VariableGenerator.d.ts +0 -5
- package/dist/storage/query-adapter/sparql/VariableGenerator.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/VariableGenerator.js +0 -14
- package/dist/storage/query-adapter/sparql/VariableGenerator.js.map +0 -1
- package/dist/storage/query-adapter/sparql/query-executor/InMemorySparqlQueryExecutor.d.ts +0 -19
- package/dist/storage/query-adapter/sparql/query-executor/InMemorySparqlQueryExecutor.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/query-executor/InMemorySparqlQueryExecutor.js +0 -90
- package/dist/storage/query-adapter/sparql/query-executor/InMemorySparqlQueryExecutor.js.map +0 -1
- package/dist/storage/query-adapter/sparql/query-executor/SparqlEndpointQueryExecutor.d.ts +0 -27
- package/dist/storage/query-adapter/sparql/query-executor/SparqlEndpointQueryExecutor.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/query-executor/SparqlEndpointQueryExecutor.js +0 -116
- package/dist/storage/query-adapter/sparql/query-executor/SparqlEndpointQueryExecutor.js.map +0 -1
- package/dist/storage/query-adapter/sparql/query-executor/SparqlQueryExecutor.d.ts +0 -34
- package/dist/storage/query-adapter/sparql/query-executor/SparqlQueryExecutor.d.ts.map +0 -1
- package/dist/storage/query-adapter/sparql/query-executor/SparqlQueryExecutor.js +0 -3
- package/dist/storage/query-adapter/sparql/query-executor/SparqlQueryExecutor.js.map +0 -1
- package/dist/tools/explain-findall-sparql.d.ts +0 -2
- package/dist/tools/explain-findall-sparql.d.ts.map +0 -1
- package/dist/tools/explain-findall-sparql.js +0 -303
- package/dist/tools/explain-findall-sparql.js.map +0 -1
- package/dist/util/PerformanceLogger.d.ts +0 -28
- package/dist/util/PerformanceLogger.d.ts.map +0 -1
- package/dist/util/PerformanceLogger.js +0 -223
- package/dist/util/PerformanceLogger.js.map +0 -1
- package/dist/util/ReadCacheHelper.d.ts +0 -14
- package/dist/util/ReadCacheHelper.d.ts.map +0 -1
- package/dist/util/ReadCacheHelper.js +0 -61
- package/dist/util/ReadCacheHelper.js.map +0 -1
- package/dist/util/SparqlUtil.d.ts +0 -72
- package/dist/util/SparqlUtil.d.ts.map +0 -1
- package/dist/util/SparqlUtil.js +0 -456
- package/dist/util/SparqlUtil.js.map +0 -1
- package/dist/util/TripleUtil.d.ts +0 -10
- package/dist/util/TripleUtil.d.ts.map +0 -1
- package/dist/util/TripleUtil.js +0 -402
- package/dist/util/TripleUtil.js.map +0 -1
- package/dist/util/Types.d.ts +0 -271
- package/dist/util/Types.d.ts.map +0 -1
- package/dist/util/Types.js +0 -3
- package/dist/util/Types.js.map +0 -1
- package/dist/util/Util.d.ts +0 -26
- package/dist/util/Util.d.ts.map +0 -1
- package/dist/util/Util.js +0 -138
- package/dist/util/Util.js.map +0 -1
- package/dist/util/Vocabularies/Shared.d.ts +0 -13
- package/dist/util/Vocabularies/Shared.d.ts.map +0 -1
- package/dist/util/Vocabularies/Shared.js +0 -96
- package/dist/util/Vocabularies/Shared.js.map +0 -1
- package/dist/util/Vocabularies/helper.d.ts +0 -5
- package/dist/util/Vocabularies/helper.d.ts.map +0 -1
- package/dist/util/Vocabularies/helper.js +0 -10
- package/dist/util/Vocabularies/helper.js.map +0 -1
- package/dist/util/Vocabularies/index.d.ts +0 -8
- package/dist/util/Vocabularies/index.d.ts.map +0 -1
- package/dist/util/Vocabularies/index.js +0 -114
- package/dist/util/Vocabularies/index.js.map +0 -1
- package/dist/util/safeJsonStringify.d.ts +0 -1
- package/dist/util/safeJsonStringify.d.ts.map +0 -1
- package/dist/util/safeJsonStringify.js +0 -19
- package/dist/util/safeJsonStringify.js.map +0 -1
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProcessManager = void 0;
|
|
4
|
-
const node_events_1 = require("node:events");
|
|
5
|
-
const logger_1 = require("../../../logger");
|
|
6
|
-
const constants_1 = require("../../constants");
|
|
7
|
-
const denoUtils_1 = require("../../denoUtils");
|
|
8
|
-
const errors_1 = require("../../errors");
|
|
9
|
-
const PermissionBuilder_1 = require("../../PermissionBuilder");
|
|
10
|
-
const PollingUtils_1 = require("../utils/PollingUtils");
|
|
11
|
-
/**
|
|
12
|
-
* Manages the lifecycle of child processes for JavaScript execution
|
|
13
|
-
*/
|
|
14
|
-
class ProcessManager extends node_events_1.EventEmitter {
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
this.logger = logger_1.Logger.getInstance();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Set a name for this process manager (used in logging)
|
|
21
|
-
*/
|
|
22
|
-
setName(name) {
|
|
23
|
-
this.name = name;
|
|
24
|
-
this.logger.setMetadata({ name, component: 'ProcessManager' });
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the current child process
|
|
28
|
-
*/
|
|
29
|
-
getProcess() {
|
|
30
|
-
return this.childProcess;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Check if the process is running
|
|
34
|
-
*/
|
|
35
|
-
isRunning() {
|
|
36
|
-
return this.childProcess !== undefined && !this.childProcess.killed;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Spawn a new child process
|
|
40
|
-
*/
|
|
41
|
-
async spawn(config) {
|
|
42
|
-
if (this.childProcess) {
|
|
43
|
-
throw new Error('Process already spawned. Call terminate() first.');
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const normalizedOptions = this.normalizeExecutionOptions(config.executionOptions);
|
|
47
|
-
const permissionConfig = this.extractPermissionConfig(normalizedOptions);
|
|
48
|
-
// Validate permissions before proceeding
|
|
49
|
-
(0, PermissionBuilder_1.validatePermissionConfig)(permissionConfig);
|
|
50
|
-
const permissions = (0, PermissionBuilder_1.buildDenoPermissions)(permissionConfig);
|
|
51
|
-
// Build command arguments
|
|
52
|
-
const commandArgs = [...constants_1.EXECUTION_CONSTANTS.denoFlags, ...permissions, config.scriptPath];
|
|
53
|
-
this.logger.debug('Spawning process with args:', commandArgs);
|
|
54
|
-
// Spawn the Deno process
|
|
55
|
-
this.childProcess = (0, denoUtils_1.spawnDenoProcess)(commandArgs);
|
|
56
|
-
this.setupProcessHandlers();
|
|
57
|
-
// Wait for process to be ready
|
|
58
|
-
await this.waitForReady(config.startupTimeout ?? 60 * 60 * 1000);
|
|
59
|
-
this.emit('ready');
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
this.childProcess = undefined;
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Terminate the child process
|
|
68
|
-
*/
|
|
69
|
-
async terminate(timeout = 3000) {
|
|
70
|
-
if (!this.childProcess || this.childProcess.killed) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this.logger.log('Terminating process');
|
|
74
|
-
// First try graceful termination
|
|
75
|
-
this.childProcess.kill(constants_1.EXECUTION_CONSTANTS.processSignals.term);
|
|
76
|
-
// Wait for process to exit gracefully
|
|
77
|
-
await new Promise(resolve => {
|
|
78
|
-
const timeoutId = setTimeout(() => {
|
|
79
|
-
if (this.childProcess && !this.childProcess.killed) {
|
|
80
|
-
this.logger.log('Force killing process after timeout');
|
|
81
|
-
this.childProcess.kill('SIGKILL');
|
|
82
|
-
}
|
|
83
|
-
resolve();
|
|
84
|
-
}, timeout);
|
|
85
|
-
this.childProcess.on('exit', () => {
|
|
86
|
-
clearTimeout(timeoutId);
|
|
87
|
-
resolve();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
this.childProcess = undefined;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Send data to the process stdin
|
|
94
|
-
*/
|
|
95
|
-
write(data) {
|
|
96
|
-
if (!this.childProcess?.stdin) {
|
|
97
|
-
throw new Error('Process stdin not available');
|
|
98
|
-
}
|
|
99
|
-
return this.childProcess.stdin.write(data);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Get process stdout stream
|
|
103
|
-
*/
|
|
104
|
-
getStdout() {
|
|
105
|
-
return this.childProcess?.stdout ?? undefined;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get process stdin stream
|
|
109
|
-
*/
|
|
110
|
-
getStdin() {
|
|
111
|
-
return this.childProcess?.stdin ?? undefined;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Register event listeners
|
|
115
|
-
*/
|
|
116
|
-
on(event, handler) {
|
|
117
|
-
return super.on(event, handler);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Remove event listeners
|
|
121
|
-
*/
|
|
122
|
-
off(event, handler) {
|
|
123
|
-
return super.off(event, handler);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Set up process event handlers
|
|
127
|
-
*/
|
|
128
|
-
setupProcessHandlers() {
|
|
129
|
-
if (!this.childProcess) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
// Handle stdout data
|
|
133
|
-
this.childProcess.stdout?.on('data', (data) => {
|
|
134
|
-
this.emit('stdout', data);
|
|
135
|
-
});
|
|
136
|
-
// Handle stderr data
|
|
137
|
-
this.childProcess.stderr?.on('data', (data) => {
|
|
138
|
-
this.emit('stderr', data);
|
|
139
|
-
});
|
|
140
|
-
// Handle process exit
|
|
141
|
-
this.childProcess.on('exit', (code, signal) => {
|
|
142
|
-
this.logger.log(`Process exited with code: ${code}, signal: ${signal}`);
|
|
143
|
-
this.emit('exit', code, signal);
|
|
144
|
-
});
|
|
145
|
-
// Handle process errors
|
|
146
|
-
this.childProcess.on('error', error => {
|
|
147
|
-
this.logger.error('Process error:', error);
|
|
148
|
-
this.emit('error', new errors_1.ProcessSpawnError(error));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Wait for the process to be ready
|
|
153
|
-
*/
|
|
154
|
-
async waitForReady(timeout) {
|
|
155
|
-
await (0, PollingUtils_1.pollUntilTrue)(() => {
|
|
156
|
-
// Check if process is running and not killed
|
|
157
|
-
if (!this.childProcess) {
|
|
158
|
-
// Process not spawned yet
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
if (this.childProcess.killed) {
|
|
162
|
-
throw new Error('Process was killed during startup');
|
|
163
|
-
}
|
|
164
|
-
// Process is running
|
|
165
|
-
return !this.childProcess.killed;
|
|
166
|
-
}, {
|
|
167
|
-
timeout,
|
|
168
|
-
// Check every 100ms or 1/10th of timeout
|
|
169
|
-
interval: Math.min(100, timeout / 10),
|
|
170
|
-
// Let process start before first check
|
|
171
|
-
initialDelay: 50
|
|
172
|
-
}, 'Process startup timed out');
|
|
173
|
-
// Additional wait for process to be fully ready (like the original logic)
|
|
174
|
-
const stabilityWait = Math.min(500, timeout / 4);
|
|
175
|
-
await new Promise(resolve => setTimeout(resolve, stabilityWait));
|
|
176
|
-
// Final check that process is still running after stability wait
|
|
177
|
-
if (!this.childProcess || this.childProcess.killed) {
|
|
178
|
-
throw new Error('Process died during startup after initial success');
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Normalize execution options with defaults
|
|
183
|
-
*/
|
|
184
|
-
normalizeExecutionOptions(options) {
|
|
185
|
-
const DEFAULT_EXECUTION_OPTIONS = {
|
|
186
|
-
timeout: 30000,
|
|
187
|
-
functionName: 'main',
|
|
188
|
-
allowNetwork: false,
|
|
189
|
-
allowedDomains: [],
|
|
190
|
-
allowEnv: false,
|
|
191
|
-
allowRead: false,
|
|
192
|
-
debugMode: false,
|
|
193
|
-
retries: 0
|
|
194
|
-
};
|
|
195
|
-
return {
|
|
196
|
-
timeout: options?.timeout ?? DEFAULT_EXECUTION_OPTIONS.timeout,
|
|
197
|
-
functionName: options?.functionName ?? DEFAULT_EXECUTION_OPTIONS.functionName,
|
|
198
|
-
allowNetwork: options?.allowNetwork ?? DEFAULT_EXECUTION_OPTIONS.allowNetwork,
|
|
199
|
-
allowedDomains: options?.allowedDomains ?? [...DEFAULT_EXECUTION_OPTIONS.allowedDomains],
|
|
200
|
-
allowEnv: options?.allowEnv ?? DEFAULT_EXECUTION_OPTIONS.allowEnv,
|
|
201
|
-
allowRead: options?.allowRead ?? DEFAULT_EXECUTION_OPTIONS.allowRead,
|
|
202
|
-
debugMode: options?.debugMode ?? DEFAULT_EXECUTION_OPTIONS.debugMode,
|
|
203
|
-
retries: options?.retries ?? DEFAULT_EXECUTION_OPTIONS.retries
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Extract permission configuration from execution options
|
|
208
|
-
*/
|
|
209
|
-
extractPermissionConfig(options) {
|
|
210
|
-
return {
|
|
211
|
-
allowNetwork: options.allowNetwork,
|
|
212
|
-
allowedDomains: options.allowedDomains,
|
|
213
|
-
allowEnv: options.allowEnv,
|
|
214
|
-
allowRead: options.allowRead
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.ProcessManager = ProcessManager;
|
|
219
|
-
//# sourceMappingURL=ProcessManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessManager.js","sourceRoot":"","sources":["../../../../src/JsExecutor/transport/process/ProcessManager.ts"],"names":[],"mappings":";;;AACA,6CAA2C;AAC3C,4CAAyC;AACzC,+CAAsD;AACtD,+CAAmD;AACnD,yCAAiD;AACjD,+DAAyF;AAEzF,wDAAsD;AAyBtD;;GAEG;AACH,MAAa,cAAe,SAAQ,0BAAY;IAK9C;QACE,KAAK,EAAE,CAAC;QAJM,WAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;IAK9C,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAY;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,gBAA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OAAO,EAAE,KAAK;YACd,YAAY,EAAE,MAAM;YACpB,YAAY,EAAE,KAAK;YACnB,cAAc,EAAE,EAAc;YAC9B,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,CAAC;SACX,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,yBAAyB,CAAC,OAAO;YAC9D,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,yBAAyB,CAAC,YAAY;YAC7E,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,yBAAyB,CAAC,YAAY;YAC7E,cAAc,EAAE,OAAO,EAAE,cAAc,IAAI,CAAE,GAAG,yBAAyB,CAAC,cAAc,CAAE;YAC1F,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,yBAAyB,CAAC,QAAQ;YACjE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,yBAAyB,CAAC,SAAS;YACpE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,yBAAyB,CAAC,SAAS;YACpE,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,yBAAyB,CAAC,OAAO;SAC/D,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,uBAAuB,CAAC,OAAmC;QACjE,OAAO;YACL,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC;IACJ,CAAC;CACF;AApPD,wCAoPC","sourcesContent":["import type { ChildProcess } from 'child_process';\nimport { EventEmitter } from 'node:events';\nimport { Logger } from '../../../logger';\nimport { EXECUTION_CONSTANTS } from '../../constants';\nimport { spawnDenoProcess } from '../../denoUtils';\nimport { ProcessSpawnError } from '../../errors';\nimport { buildDenoPermissions, validatePermissionConfig } from '../../PermissionBuilder';\nimport type { ExecutionOptions, PermissionConfig } from '../../types';\nimport { pollUntilTrue } from '../utils/PollingUtils';\n\n/**\n * Events emitted by the ProcessManager\n */\nexport interface ProcessManagerEvents {\n stdout: (data: Buffer) => void;\n stderr: (data: Buffer) => void;\n exit: (code: number | null, signal: NodeJS.Signals | null) => void;\n error: (error: Error) => void;\n ready: () => void;\n}\n\n/**\n * Configuration for process spawning\n */\nexport interface ProcessConfig {\n /** Script path to execute */\n scriptPath: string;\n /** Execution options */\n executionOptions?: ExecutionOptions;\n /** Timeout for process startup */\n startupTimeout?: number;\n}\n\n/**\n * Manages the lifecycle of child processes for JavaScript execution\n */\nexport class ProcessManager extends EventEmitter {\n private childProcess?: ChildProcess;\n public readonly logger = Logger.getInstance();\n private name?: string;\n\n public constructor() {\n super();\n }\n\n /**\n * Set a name for this process manager (used in logging)\n */\n public setName(name: string): void {\n this.name = name;\n this.logger.setMetadata({ name, component: 'ProcessManager' });\n }\n\n /**\n * Get the current child process\n */\n public getProcess(): ChildProcess | undefined {\n return this.childProcess;\n }\n\n /**\n * Check if the process is running\n */\n public isRunning(): boolean {\n return this.childProcess !== undefined && !this.childProcess.killed;\n }\n\n /**\n * Spawn a new child process\n */\n public async spawn(config: ProcessConfig): Promise<void> {\n if (this.childProcess) {\n throw new Error('Process already spawned. Call terminate() first.');\n }\n\n try {\n const normalizedOptions = this.normalizeExecutionOptions(config.executionOptions);\n const permissionConfig = this.extractPermissionConfig(normalizedOptions);\n\n // Validate permissions before proceeding\n validatePermissionConfig(permissionConfig);\n\n const permissions = buildDenoPermissions(permissionConfig);\n\n // Build command arguments\n const commandArgs = [ ...EXECUTION_CONSTANTS.denoFlags, ...permissions, config.scriptPath ];\n\n this.logger.debug('Spawning process with args:', commandArgs);\n\n // Spawn the Deno process\n this.childProcess = spawnDenoProcess(commandArgs);\n\n this.setupProcessHandlers();\n\n // Wait for process to be ready\n await this.waitForReady(config.startupTimeout ?? 60 * 60 * 1000);\n\n this.emit('ready');\n } catch (error: unknown) {\n this.childProcess = undefined;\n throw error;\n }\n }\n\n /**\n * Terminate the child process\n */\n public async terminate(timeout = 3000): Promise<void> {\n if (!this.childProcess || this.childProcess.killed) {\n return;\n }\n\n this.logger.log('Terminating process');\n\n // First try graceful termination\n this.childProcess.kill(EXECUTION_CONSTANTS.processSignals.term);\n\n // Wait for process to exit gracefully\n await new Promise<void>(resolve => {\n const timeoutId = setTimeout(() => {\n if (this.childProcess && !this.childProcess.killed) {\n this.logger.log('Force killing process after timeout');\n this.childProcess.kill('SIGKILL');\n }\n resolve();\n }, timeout);\n\n this.childProcess!.on('exit', () => {\n clearTimeout(timeoutId);\n resolve();\n });\n });\n\n this.childProcess = undefined;\n }\n\n /**\n * Send data to the process stdin\n */\n public write(data: string): boolean {\n if (!this.childProcess?.stdin) {\n throw new Error('Process stdin not available');\n }\n return this.childProcess.stdin.write(data);\n }\n\n /**\n * Get process stdout stream\n */\n public getStdout(): NodeJS.ReadableStream | undefined {\n return this.childProcess?.stdout ?? undefined;\n }\n\n /**\n * Get process stdin stream\n */\n public getStdin(): NodeJS.WritableStream | undefined {\n return this.childProcess?.stdin ?? undefined;\n }\n\n /**\n * Register event listeners\n */\n public on<TKey extends keyof ProcessManagerEvents>(event: TKey, handler: ProcessManagerEvents[TKey]): this {\n return super.on(event, handler);\n }\n\n /**\n * Remove event listeners\n */\n public off<TKey extends keyof ProcessManagerEvents>(event: TKey, handler: ProcessManagerEvents[TKey]): this {\n return super.off(event, handler);\n }\n\n /**\n * Set up process event handlers\n */\n private setupProcessHandlers(): void {\n if (!this.childProcess) {\n return;\n }\n\n // Handle stdout data\n this.childProcess.stdout?.on('data', (data: Buffer) => {\n this.emit('stdout', data);\n });\n\n // Handle stderr data\n this.childProcess.stderr?.on('data', (data: Buffer) => {\n this.emit('stderr', data);\n });\n\n // Handle process exit\n this.childProcess.on('exit', (code, signal) => {\n this.logger.log(`Process exited with code: ${code}, signal: ${signal}`);\n this.emit('exit', code, signal);\n });\n\n // Handle process errors\n this.childProcess.on('error', error => {\n this.logger.error('Process error:', error);\n this.emit('error', new ProcessSpawnError(error));\n });\n }\n\n /**\n * Wait for the process to be ready\n */\n private async waitForReady(timeout: number): Promise<void> {\n await pollUntilTrue(\n () => {\n // Check if process is running and not killed\n if (!this.childProcess) {\n // Process not spawned yet\n return false;\n }\n if (this.childProcess.killed) {\n throw new Error('Process was killed during startup');\n }\n // Process is running\n return !this.childProcess.killed;\n },\n {\n timeout,\n // Check every 100ms or 1/10th of timeout\n interval: Math.min(100, timeout / 10),\n // Let process start before first check\n initialDelay: 50\n },\n 'Process startup timed out'\n );\n\n // Additional wait for process to be fully ready (like the original logic)\n const stabilityWait = Math.min(500, timeout / 4);\n await new Promise<void>(resolve => setTimeout(resolve, stabilityWait));\n\n // Final check that process is still running after stability wait\n if (!this.childProcess || this.childProcess.killed) {\n throw new Error('Process died during startup after initial success');\n }\n }\n\n /**\n * Normalize execution options with defaults\n */\n private normalizeExecutionOptions(options?: ExecutionOptions): Required<ExecutionOptions> {\n const DEFAULT_EXECUTION_OPTIONS = {\n timeout: 30000,\n functionName: 'main',\n allowNetwork: false,\n allowedDomains: [] as string[],\n allowEnv: false,\n allowRead: false,\n debugMode: false,\n retries: 0\n };\n\n return {\n timeout: options?.timeout ?? DEFAULT_EXECUTION_OPTIONS.timeout,\n functionName: options?.functionName ?? DEFAULT_EXECUTION_OPTIONS.functionName,\n allowNetwork: options?.allowNetwork ?? DEFAULT_EXECUTION_OPTIONS.allowNetwork,\n allowedDomains: options?.allowedDomains ?? [ ...DEFAULT_EXECUTION_OPTIONS.allowedDomains ],\n allowEnv: options?.allowEnv ?? DEFAULT_EXECUTION_OPTIONS.allowEnv,\n allowRead: options?.allowRead ?? DEFAULT_EXECUTION_OPTIONS.allowRead,\n debugMode: options?.debugMode ?? DEFAULT_EXECUTION_OPTIONS.debugMode,\n retries: options?.retries ?? DEFAULT_EXECUTION_OPTIONS.retries\n };\n }\n\n /**\n * Extract permission configuration from execution options\n */\n private extractPermissionConfig(options: Required<ExecutionOptions>): PermissionConfig {\n return {\n allowNetwork: options.allowNetwork,\n allowedDomains: options.allowedDomains,\n allowEnv: options.allowEnv,\n allowRead: options.allowRead\n };\n }\n}\n"]}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'node:events';
|
|
3
|
-
/**
|
|
4
|
-
* Bidirectional StdioTransport for child processes
|
|
5
|
-
* This class handles both server (receiving requests) and client (sending requests) functionality
|
|
6
|
-
* over a single stdio channel with proper message routing.
|
|
7
|
-
*
|
|
8
|
-
* Usage in child process:
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const transport = new ChildStdioTransport();
|
|
11
|
-
*
|
|
12
|
-
* // Register methods that parent can call
|
|
13
|
-
* transport.registerMethod('ping', async () => 'pong');
|
|
14
|
-
*
|
|
15
|
-
* // Make requests to parent
|
|
16
|
-
* const result = await transport.request('getTime');
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare class ChildStdioTransport extends EventEmitter {
|
|
20
|
-
private readonly server;
|
|
21
|
-
private readonly client;
|
|
22
|
-
private readonly logger;
|
|
23
|
-
private readonly messageBuffer;
|
|
24
|
-
private name?;
|
|
25
|
-
private initialized;
|
|
26
|
-
constructor();
|
|
27
|
-
/**
|
|
28
|
-
* Set a name for this transport (used in logging)
|
|
29
|
-
*/
|
|
30
|
-
setName(name: string): void;
|
|
31
|
-
/**
|
|
32
|
-
* Initialize the bidirectional transport
|
|
33
|
-
* This should be called once after setting up all methods
|
|
34
|
-
*/
|
|
35
|
-
initialize(): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Register a method that the parent can call
|
|
38
|
-
* @param method - Method name
|
|
39
|
-
* @param handler - Method handler function
|
|
40
|
-
*/
|
|
41
|
-
registerMethod<TParams = any, TResult = any>(method: string, handler: (params: TParams) => Promise<TResult> | TResult): void;
|
|
42
|
-
/**
|
|
43
|
-
* Send a request to the parent process
|
|
44
|
-
* @param method - Method name
|
|
45
|
-
* @param params - Method parameters
|
|
46
|
-
* @param options - Request options
|
|
47
|
-
* @returns Promise resolving to the response
|
|
48
|
-
*/
|
|
49
|
-
request<TParams = any, TResult = any>(method: string, params?: TParams, options?: {
|
|
50
|
-
timeout?: number;
|
|
51
|
-
}): Promise<TResult>;
|
|
52
|
-
/**
|
|
53
|
-
* Send a notification to the parent process (no response expected)
|
|
54
|
-
* @param method - Method name
|
|
55
|
-
* @param params - Method parameters
|
|
56
|
-
*/
|
|
57
|
-
notify<TParams = any>(method: string, params?: TParams): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Get transport statistics
|
|
60
|
-
*/
|
|
61
|
-
getStats(): {
|
|
62
|
-
serverMethods: number;
|
|
63
|
-
pendingRequests: number;
|
|
64
|
-
initialized: boolean;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Close the transport and cleanup resources
|
|
68
|
-
*/
|
|
69
|
-
close(): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Set up stdio communication handlers
|
|
72
|
-
*/
|
|
73
|
-
private setupStdioCommunication;
|
|
74
|
-
/**
|
|
75
|
-
* Handle incoming message and route to appropriate handler
|
|
76
|
-
*/
|
|
77
|
-
private handleIncomingMessage;
|
|
78
|
-
/**
|
|
79
|
-
* Send a message to the parent process
|
|
80
|
-
*/
|
|
81
|
-
private sendMessage;
|
|
82
|
-
/**
|
|
83
|
-
* Set up event handlers
|
|
84
|
-
*/
|
|
85
|
-
private setupEventHandlers;
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=ChildStdioTransport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChildStdioTransport.d.ts","sourceRoot":"","sources":["../../../../src/JsExecutor/transport/stdio/ChildStdioTransport.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAsC3C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IAC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AAO,CAAC,kBAAkB;CAW3B"}
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChildStdioTransport = void 0;
|
|
4
|
-
/* eslint-disable indent */
|
|
5
|
-
const node_events_1 = require("node:events");
|
|
6
|
-
const JsonRpcClient_1 = require("../../jsonRpc/JsonRpcClient");
|
|
7
|
-
const JsonRpcServer_1 = require("../../jsonRpc/JsonRpcServer");
|
|
8
|
-
const MessageUtils_1 = require("../utils/MessageUtils");
|
|
9
|
-
/**
|
|
10
|
-
* Custom logger that outputs to stderr to avoid contaminating stdout JSON-RPC channel
|
|
11
|
-
*/
|
|
12
|
-
class ChildProcessLogger {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.metadata = {};
|
|
15
|
-
}
|
|
16
|
-
setMetadata(metadata) {
|
|
17
|
-
this.metadata = { ...this.metadata, ...metadata };
|
|
18
|
-
}
|
|
19
|
-
log(message, data) {
|
|
20
|
-
const logEntry = {
|
|
21
|
-
message,
|
|
22
|
-
metadata: this.metadata,
|
|
23
|
-
...data && { data }
|
|
24
|
-
};
|
|
25
|
-
// Use stderr to avoid contaminating stdout JSON-RPC channel
|
|
26
|
-
process.stderr.write(`${message} ${JSON.stringify(logEntry.metadata)} ${data ? JSON.stringify(data) : ''}\n`);
|
|
27
|
-
}
|
|
28
|
-
error(message, error) {
|
|
29
|
-
const logEntry = {
|
|
30
|
-
level: 'error',
|
|
31
|
-
message,
|
|
32
|
-
metadata: this.metadata,
|
|
33
|
-
...error && { error: error.message, stack: error.stack }
|
|
34
|
-
};
|
|
35
|
-
process.stderr.write(`ERROR: ${JSON.stringify(logEntry)}\n`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Bidirectional StdioTransport for child processes
|
|
40
|
-
* This class handles both server (receiving requests) and client (sending requests) functionality
|
|
41
|
-
* over a single stdio channel with proper message routing.
|
|
42
|
-
*
|
|
43
|
-
* Usage in child process:
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const transport = new ChildStdioTransport();
|
|
46
|
-
*
|
|
47
|
-
* // Register methods that parent can call
|
|
48
|
-
* transport.registerMethod('ping', async () => 'pong');
|
|
49
|
-
*
|
|
50
|
-
* // Make requests to parent
|
|
51
|
-
* const result = await transport.request('getTime');
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
class ChildStdioTransport extends node_events_1.EventEmitter {
|
|
55
|
-
constructor() {
|
|
56
|
-
super();
|
|
57
|
-
this.logger = new ChildProcessLogger();
|
|
58
|
-
this.messageBuffer = new MessageUtils_1.MessageBuffer();
|
|
59
|
-
this.initialized = false;
|
|
60
|
-
this.server = new JsonRpcServer_1.JsonRpcServer({
|
|
61
|
-
requestTimeout: 60 * 60 * 1000
|
|
62
|
-
});
|
|
63
|
-
this.client = new JsonRpcClient_1.JsonRpcClient({
|
|
64
|
-
defaultTimeout: 60 * 60 * 1000
|
|
65
|
-
});
|
|
66
|
-
// Set up the client transport that routes through our stdio
|
|
67
|
-
const clientTransport = {
|
|
68
|
-
send: async (message) => {
|
|
69
|
-
this.sendMessage(message);
|
|
70
|
-
},
|
|
71
|
-
onMessage() {
|
|
72
|
-
// The message routing will handle client responses automatically
|
|
73
|
-
},
|
|
74
|
-
async close() {
|
|
75
|
-
// Nothing to close for stdio
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
this.client.setTransport(clientTransport);
|
|
79
|
-
this.setupEventHandlers();
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Set a name for this transport (used in logging)
|
|
83
|
-
*/
|
|
84
|
-
setName(name) {
|
|
85
|
-
this.name = name;
|
|
86
|
-
this.logger.setMetadata({ name, transport: 'ChildStdioTransport' });
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Initialize the bidirectional transport
|
|
90
|
-
* This should be called once after setting up all methods
|
|
91
|
-
*/
|
|
92
|
-
async initialize() {
|
|
93
|
-
if (this.initialized) {
|
|
94
|
-
throw new Error('Transport already initialized');
|
|
95
|
-
}
|
|
96
|
-
this.initialized = true;
|
|
97
|
-
this.setupStdioCommunication();
|
|
98
|
-
this.logger.log('Transport initialized');
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Register a method that the parent can call
|
|
102
|
-
* @param method - Method name
|
|
103
|
-
* @param handler - Method handler function
|
|
104
|
-
*/
|
|
105
|
-
registerMethod(method, handler) {
|
|
106
|
-
this.server.registerMethod(method, handler);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Send a request to the parent process
|
|
110
|
-
* @param method - Method name
|
|
111
|
-
* @param params - Method parameters
|
|
112
|
-
* @param options - Request options
|
|
113
|
-
* @returns Promise resolving to the response
|
|
114
|
-
*/
|
|
115
|
-
async request(method, params, options) {
|
|
116
|
-
if (!this.initialized) {
|
|
117
|
-
throw new Error('Transport not initialized. Call initialize() first.');
|
|
118
|
-
}
|
|
119
|
-
return this.client.request(method, params, options);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Send a notification to the parent process (no response expected)
|
|
123
|
-
* @param method - Method name
|
|
124
|
-
* @param params - Method parameters
|
|
125
|
-
*/
|
|
126
|
-
async notify(method, params) {
|
|
127
|
-
if (!this.initialized) {
|
|
128
|
-
throw new Error('Transport not initialized. Call initialize() first.');
|
|
129
|
-
}
|
|
130
|
-
return this.client.notify(method, params);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Get transport statistics
|
|
134
|
-
*/
|
|
135
|
-
getStats() {
|
|
136
|
-
return {
|
|
137
|
-
serverMethods: 0,
|
|
138
|
-
pendingRequests: this.client.getStats().pendingRequests,
|
|
139
|
-
initialized: this.initialized
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Close the transport and cleanup resources
|
|
144
|
-
*/
|
|
145
|
-
async close() {
|
|
146
|
-
await this.client.close();
|
|
147
|
-
this.initialized = false;
|
|
148
|
-
this.removeAllListeners();
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Set up stdio communication handlers
|
|
152
|
-
*/
|
|
153
|
-
setupStdioCommunication() {
|
|
154
|
-
// Handle incoming data from parent
|
|
155
|
-
process.stdin.on('data', async (data) => {
|
|
156
|
-
const messages = this.messageBuffer.addData(data.toString());
|
|
157
|
-
for (const messageData of messages) {
|
|
158
|
-
await this.handleIncomingMessage(messageData);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
// Handle process termination gracefully
|
|
162
|
-
process.on('SIGTERM', () => {
|
|
163
|
-
this.close().finally(() => process.exit(0));
|
|
164
|
-
});
|
|
165
|
-
process.on('SIGINT', () => {
|
|
166
|
-
this.close().finally(() => process.exit(0));
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Handle incoming message and route to appropriate handler
|
|
171
|
-
*/
|
|
172
|
-
async handleIncomingMessage(messageData) {
|
|
173
|
-
try {
|
|
174
|
-
const message = JSON.parse(messageData);
|
|
175
|
-
// Check if this is a response to our request (has 'result' or 'error' and 'id')
|
|
176
|
-
if ((0, MessageUtils_1.isResponse)(message)) {
|
|
177
|
-
// This is a response to a request we made - route to client
|
|
178
|
-
this.logger.log(`Routing response to client: ${message.id}`);
|
|
179
|
-
await this.client.handleIncomingMessage(messageData);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
// This is a request or notification for us - route to server
|
|
183
|
-
this.logger.log(`Routing request to server: ${message.method}`);
|
|
184
|
-
const response = await this.server.processMessage(messageData);
|
|
185
|
-
this.logger.log('Sending response to parent process', response);
|
|
186
|
-
// Only send response if there is one (requests get responses, notifications don't)
|
|
187
|
-
if (response) {
|
|
188
|
-
this.sendMessage(JSON.stringify(response));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
process.stderr.write(`Error processing message: ${error.message}\n`);
|
|
194
|
-
this.emit('error', error);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Send a message to the parent process
|
|
199
|
-
*/
|
|
200
|
-
sendMessage(message) {
|
|
201
|
-
this.logger.log(`Sending: ${message}`);
|
|
202
|
-
process.stdout.write(`${message}\n`);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Set up event handlers
|
|
206
|
-
*/
|
|
207
|
-
setupEventHandlers() {
|
|
208
|
-
this.server.on('error', (error) => {
|
|
209
|
-
this.logger.error('Server error', error);
|
|
210
|
-
this.emit('error', error);
|
|
211
|
-
});
|
|
212
|
-
this.client.on('error', (error) => {
|
|
213
|
-
this.logger.error('Client error', error);
|
|
214
|
-
this.emit('error', error);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.ChildStdioTransport = ChildStdioTransport;
|
|
219
|
-
//# sourceMappingURL=ChildStdioTransport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChildStdioTransport.js","sourceRoot":"","sources":["../../../../src/JsExecutor/transport/stdio/ChildStdioTransport.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,6CAA2C;AAE3C,+DAA4D;AAC5D,+DAA4D;AAC5D,wDAAkE;AAElE;;GAEG;AACH,MAAM,kBAAkB;IAAxB;QAEU,aAAQ,GAAwB,EAAE,CAAC;IAyB7C,CAAC;IAvBQ,WAAW,CAAC,QAA6B;QAC9C,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC;IACpD,CAAC;IAEM,GAAG,CAAC,OAAe,EAAE,IAAU;QACpC,MAAM,QAAQ,GAAG;YACf,OAAO;YACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG,IAAI,IAAI,EAAE,IAAI,EAAE;SACpB,CAAC;QACF,4DAA4D;QAC5D,OAAO,CAAC,MAAM,CAAC,KAAK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EAAE;YAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YACzC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAQ,EAAE;YAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YACzC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnMD,kDAmMC","sourcesContent":["/* eslint-disable indent */\nimport { EventEmitter } from 'node:events';\nimport type { ClientTransport } from '../../jsonRpc/JsonRpcClient';\nimport { JsonRpcClient } from '../../jsonRpc/JsonRpcClient';\nimport { JsonRpcServer } from '../../jsonRpc/JsonRpcServer';\nimport { isResponse, MessageBuffer } from '../utils/MessageUtils';\n\n/**\n * Custom logger that outputs to stderr to avoid contaminating stdout JSON-RPC channel\n */\nclass ChildProcessLogger {\n private readonly name?: string;\n private metadata: Record<string, any> = {};\n\n public setMetadata(metadata: Record<string, any>): void {\n this.metadata = { ...this.metadata, ...metadata };\n }\n\n public log(message: string, data?: any): void {\n const logEntry = {\n message,\n metadata: this.metadata,\n ...data && { data }\n };\n // Use stderr to avoid contaminating stdout JSON-RPC channel\n process.stderr.write(`${message} ${JSON.stringify(logEntry.metadata)} ${data ? JSON.stringify(data) : ''}\\n`);\n }\n\n public error(message: string, error?: Error): void {\n const logEntry = {\n level: 'error',\n message,\n metadata: this.metadata,\n ...error && { error: error.message, stack: error.stack }\n };\n process.stderr.write(`ERROR: ${JSON.stringify(logEntry)}\\n`);\n }\n}\n\n/**\n * Bidirectional StdioTransport for child processes\n * This class handles both server (receiving requests) and client (sending requests) functionality\n * over a single stdio channel with proper message routing.\n *\n * Usage in child process:\n * ```typescript\n * const transport = new ChildStdioTransport();\n *\n * // Register methods that parent can call\n * transport.registerMethod('ping', async () => 'pong');\n *\n * // Make requests to parent\n * const result = await transport.request('getTime');\n * ```\n */\nexport class ChildStdioTransport extends EventEmitter {\n private readonly server: JsonRpcServer;\n private readonly client: JsonRpcClient;\n private readonly logger = new ChildProcessLogger();\n private readonly messageBuffer = new MessageBuffer();\n private name?: string;\n private initialized = false;\n\n public constructor() {\n super();\n this.server = new JsonRpcServer({\n requestTimeout: 60 * 60 * 1000\n });\n this.client = new JsonRpcClient({\n defaultTimeout: 60 * 60 * 1000\n });\n\n // Set up the client transport that routes through our stdio\n const clientTransport: ClientTransport = {\n send: async(message: string): Promise<void> => {\n this.sendMessage(message);\n },\n onMessage(): void {\n // The message routing will handle client responses automatically\n },\n async close(): Promise<void> {\n // Nothing to close for stdio\n }\n };\n\n this.client.setTransport(clientTransport);\n this.setupEventHandlers();\n }\n\n /**\n * Set a name for this transport (used in logging)\n */\n public setName(name: string): void {\n this.name = name;\n this.logger.setMetadata({ name, transport: 'ChildStdioTransport' });\n }\n\n /**\n * Initialize the bidirectional transport\n * This should be called once after setting up all methods\n */\n public async initialize(): Promise<void> {\n if (this.initialized) {\n throw new Error('Transport already initialized');\n }\n\n this.initialized = true;\n this.setupStdioCommunication();\n this.logger.log('Transport initialized');\n }\n\n /**\n * Register a method that the parent can call\n * @param method - Method name\n * @param handler - Method handler function\n */\n public registerMethod<TParams = any, TResult = any>(\n method: string,\n handler: (params: TParams) => Promise<TResult> | TResult\n ): void {\n this.server.registerMethod(method, handler);\n }\n\n /**\n * Send a request to the parent process\n * @param method - Method name\n * @param params - Method parameters\n * @param options - Request options\n * @returns Promise resolving to the response\n */\n public async request<TParams = any, TResult = any>(\n method: string,\n params?: TParams,\n options?: { timeout?: number }\n ): Promise<TResult> {\n if (!this.initialized) {\n throw new Error('Transport not initialized. Call initialize() first.');\n }\n return this.client.request<TParams, TResult>(method, params, options);\n }\n\n /**\n * Send a notification to the parent process (no response expected)\n * @param method - Method name\n * @param params - Method parameters\n */\n public async notify<TParams = any>(method: string, params?: TParams): Promise<void> {\n if (!this.initialized) {\n throw new Error('Transport not initialized. Call initialize() first.');\n }\n return this.client.notify(method, params);\n }\n\n /**\n * Get transport statistics\n */\n public getStats(): {\n serverMethods: number;\n pendingRequests: number;\n initialized: boolean;\n } {\n return {\n serverMethods: 0,\n pendingRequests: this.client.getStats().pendingRequests,\n initialized: this.initialized\n };\n }\n\n /**\n * Close the transport and cleanup resources\n */\n public async close(): Promise<void> {\n await this.client.close();\n this.initialized = false;\n this.removeAllListeners();\n }\n\n /**\n * Set up stdio communication handlers\n */\n private setupStdioCommunication(): void {\n // Handle incoming data from parent\n process.stdin.on('data', async(data: Buffer): Promise<void> => {\n const messages = this.messageBuffer.addData(data.toString());\n\n for (const messageData of messages) {\n await this.handleIncomingMessage(messageData);\n }\n });\n\n // Handle process termination gracefully\n process.on('SIGTERM', (): void => {\n this.close().finally((): void => process.exit(0));\n });\n\n process.on('SIGINT', (): void => {\n this.close().finally((): void => process.exit(0));\n });\n }\n\n /**\n * Handle incoming message and route to appropriate handler\n */\n private async handleIncomingMessage(messageData: string): Promise<void> {\n try {\n const message = JSON.parse(messageData);\n\n // Check if this is a response to our request (has 'result' or 'error' and 'id')\n if (isResponse(message)) {\n // This is a response to a request we made - route to client\n this.logger.log(`Routing response to client: ${message.id}`);\n await this.client.handleIncomingMessage(messageData);\n } else {\n // This is a request or notification for us - route to server\n this.logger.log(`Routing request to server: ${message.method}`);\n const response = await this.server.processMessage(messageData);\n this.logger.log('Sending response to parent process', response);\n // Only send response if there is one (requests get responses, notifications don't)\n if (response) {\n this.sendMessage(JSON.stringify(response));\n }\n }\n } catch (error: unknown) {\n process.stderr.write(`Error processing message: ${(error as Error).message}\\n`);\n this.emit('error', error);\n }\n }\n\n /**\n * Send a message to the parent process\n */\n private sendMessage(message: string): void {\n this.logger.log(`Sending: ${message}`);\n process.stdout.write(`${message}\\n`);\n }\n\n /**\n * Set up event handlers\n */\n private setupEventHandlers(): void {\n this.server.on('error', (error: Error): void => {\n this.logger.error('Server error', error);\n this.emit('error', error);\n });\n\n this.client.on('error', (error: Error): void => {\n this.logger.error('Client error', error);\n this.emit('error', error);\n });\n }\n}\n"]}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { ClientTransport } from '../../jsonRpc/JsonRpcClient';
|
|
2
|
-
import type { JsonRpcServer } from '../../jsonRpc/JsonRpcServer';
|
|
3
|
-
import type { ExecutionOptions } from '../../types';
|
|
4
|
-
import { BaseTransport } from '../base/BaseTransport';
|
|
5
|
-
import { ProcessManager } from '../process/ProcessManager';
|
|
6
|
-
import type { TransportConfig } from '../Transport';
|
|
7
|
-
/**
|
|
8
|
-
* Client transport implementation for stdio communication
|
|
9
|
-
*/
|
|
10
|
-
export declare class StdioClientTransport implements ClientTransport {
|
|
11
|
-
private readonly processManager;
|
|
12
|
-
private messageHandler?;
|
|
13
|
-
private name?;
|
|
14
|
-
private readonly logger;
|
|
15
|
-
constructor(processManager: ProcessManager);
|
|
16
|
-
setName(name: string): void;
|
|
17
|
-
send(message: string): Promise<void>;
|
|
18
|
-
onMessage(handler: (message: string) => void): void;
|
|
19
|
-
close(): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* StdioTransport implementation for parent process communication with child
|
|
23
|
-
* This is the parent-side transport that manages a child process
|
|
24
|
-
*/
|
|
25
|
-
export declare class ParentStdioTransport extends BaseTransport {
|
|
26
|
-
private readonly processManager;
|
|
27
|
-
private readonly server;
|
|
28
|
-
private readonly client;
|
|
29
|
-
private readonly clientTransport;
|
|
30
|
-
private readonly executorScriptPath;
|
|
31
|
-
private readonly messageBuffer;
|
|
32
|
-
constructor(executorScriptPath: string, server: JsonRpcServer);
|
|
33
|
-
/**
|
|
34
|
-
* Initialize the transport connection
|
|
35
|
-
*/
|
|
36
|
-
initialize(config?: TransportConfig, executionOptions?: ExecutionOptions): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Send a message through the transport
|
|
39
|
-
*/
|
|
40
|
-
send<TRequest, TResponse>(message: TRequest): Promise<TResponse>;
|
|
41
|
-
/**
|
|
42
|
-
* Make a direct RPC request to the child process
|
|
43
|
-
*/
|
|
44
|
-
request<TParams = any, TResult = any>(method: string, params?: TParams, options?: {
|
|
45
|
-
timeout?: number;
|
|
46
|
-
retries?: number;
|
|
47
|
-
}): Promise<TResult>;
|
|
48
|
-
/**
|
|
49
|
-
* Send a notification to the child process (no response expected)
|
|
50
|
-
*/
|
|
51
|
-
notify<TParams = any>(method: string, params?: TParams): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Close the transport connection
|
|
54
|
-
*/
|
|
55
|
-
close(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Check if the transport is ready for communication
|
|
58
|
-
*/
|
|
59
|
-
isReady(): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Set up server methods for handling incoming requests from Deno process
|
|
62
|
-
*/
|
|
63
|
-
private setupServerMethods;
|
|
64
|
-
/**
|
|
65
|
-
* Set up event handlers
|
|
66
|
-
*/
|
|
67
|
-
private setupEventHandlers;
|
|
68
|
-
/**
|
|
69
|
-
* Set up process communication handlers
|
|
70
|
-
*/
|
|
71
|
-
private setupProcessCommunication;
|
|
72
|
-
/**
|
|
73
|
-
* Handle incoming message from Deno process with bidirectional routing
|
|
74
|
-
*/
|
|
75
|
-
private handleIncomingMessage;
|
|
76
|
-
/**
|
|
77
|
-
* Wait for the process to be ready
|
|
78
|
-
*/
|
|
79
|
-
private waitForReady;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=ParentStdioTransport.d.ts.map
|