@comake/skl-js-engine 1.0.8 → 1.1.0
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/JsExecutor/PermissionBuilder.d.ts +13 -0
- package/dist/JsExecutor/PermissionBuilder.js +58 -0
- package/dist/JsExecutor/PermissionBuilder.js.map +1 -0
- package/dist/JsExecutor/constants.d.ts +26 -0
- package/dist/JsExecutor/constants.js +30 -0
- package/dist/JsExecutor/constants.js.map +1 -0
- package/dist/JsExecutor/denoUtils.d.ts +9 -0
- package/dist/JsExecutor/denoUtils.js +24 -0
- package/dist/JsExecutor/denoUtils.js.map +1 -0
- package/dist/JsExecutor/errors.d.ts +39 -0
- package/dist/JsExecutor/errors.js +67 -0
- package/dist/JsExecutor/errors.js.map +1 -0
- package/dist/JsExecutor/examples/basic/index.d.ts +0 -0
- package/dist/JsExecutor/examples/basic/index.js +46 -0
- package/dist/JsExecutor/examples/basic/index.js.map +1 -0
- package/dist/JsExecutor/examples/basic/process.d.ts +0 -0
- package/dist/JsExecutor/examples/basic/process.js +34 -0
- package/dist/JsExecutor/examples/basic/process.js.map +1 -0
- package/dist/JsExecutor/examples/jsExecutor/index.d.ts +1 -0
- package/dist/JsExecutor/examples/jsExecutor/index.js +48 -0
- package/dist/JsExecutor/examples/jsExecutor/index.js.map +1 -0
- package/dist/JsExecutor/examples/jsExecutor/process.d.ts +1 -0
- package/dist/JsExecutor/examples/jsExecutor/process.js +59 -0
- package/dist/JsExecutor/examples/jsExecutor/process.js.map +1 -0
- package/dist/JsExecutor/index.d.ts +6 -0
- package/dist/JsExecutor/index.js +36 -0
- package/dist/JsExecutor/index.js.map +1 -0
- package/dist/JsExecutor/jsExecutor.d.ts +67 -0
- package/dist/JsExecutor/jsExecutor.js +159 -0
- package/dist/JsExecutor/jsExecutor.js.map +1 -0
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.d.ts +164 -0
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.js +334 -0
- package/dist/JsExecutor/jsonRpc/JsonRpcClient.js.map +1 -0
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.d.ts +124 -0
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.js +391 -0
- package/dist/JsExecutor/jsonRpc/JsonRpcServer.js.map +1 -0
- package/dist/JsExecutor/jsonRpc/index.d.ts +3 -0
- package/dist/JsExecutor/jsonRpc/index.js +23 -0
- package/dist/JsExecutor/jsonRpc/index.js.map +1 -0
- package/dist/JsExecutor/jsonRpc/types.d.ts +192 -0
- package/dist/JsExecutor/jsonRpc/types.js +37 -0
- package/dist/JsExecutor/jsonRpc/types.js.map +1 -0
- package/dist/JsExecutor/transport/StdioTransport.d.ts +226 -0
- package/dist/JsExecutor/transport/StdioTransport.js +634 -0
- package/dist/JsExecutor/transport/StdioTransport.js.map +1 -0
- package/dist/JsExecutor/transport/Transport.d.ts +71 -0
- package/dist/JsExecutor/transport/Transport.js +14 -0
- package/dist/JsExecutor/transport/Transport.js.map +1 -0
- package/dist/JsExecutor/transport/base/BaseTransport.d.ts +50 -0
- package/dist/JsExecutor/transport/base/BaseTransport.js +68 -0
- package/dist/JsExecutor/transport/base/BaseTransport.js.map +1 -0
- package/dist/JsExecutor/transport/index.d.ts +12 -0
- package/dist/JsExecutor/transport/index.js +36 -0
- package/dist/JsExecutor/transport/index.js.map +1 -0
- package/dist/JsExecutor/transport/process/ProcessManager.d.ts +95 -0
- package/dist/JsExecutor/transport/process/ProcessManager.js +214 -0
- package/dist/JsExecutor/transport/process/ProcessManager.js.map +1 -0
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.d.ts +86 -0
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.js +215 -0
- package/dist/JsExecutor/transport/stdio/ChildStdioTransport.js.map +1 -0
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.d.ts +80 -0
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.js +263 -0
- package/dist/JsExecutor/transport/stdio/ParentStdioTransport.js.map +1 -0
- package/dist/JsExecutor/transport/utils/MessageUtils.d.ts +67 -0
- package/dist/JsExecutor/transport/utils/MessageUtils.js +135 -0
- package/dist/JsExecutor/transport/utils/MessageUtils.js.map +1 -0
- package/dist/JsExecutor/types.d.ts +112 -0
- package/dist/JsExecutor/types.js +3 -0
- package/dist/JsExecutor/types.js.map +1 -0
- package/dist/SklEngine.d.ts +9 -5
- package/dist/SklEngine.js +84 -87
- package/dist/SklEngine.js.map +1 -1
- package/dist/SklEngineOptions.d.ts +4 -0
- package/dist/constants.d.ts +1 -1
- package/dist/customCapabilities.d.ts +21 -0
- package/dist/customCapabilities.js +45 -0
- package/dist/customCapabilities.js.map +1 -0
- package/dist/examples/customCapabilitiesExample.d.ts +1 -0
- package/dist/examples/customCapabilitiesExample.js +57 -0
- package/dist/examples/customCapabilitiesExample.js.map +1 -0
- package/dist/executor.js +9 -3
- package/dist/index.d.ts +13 -11
- package/dist/index.js +20 -16
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +5 -1
- package/dist/logger.js +21 -4
- package/dist/logger.js.map +1 -1
- package/dist/util/Vocabularies/Shared.d.ts +1 -1
- package/dist/util/Vocabularies/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/Jsexecutor.d.ts +0 -77
- package/dist/Jsexecutor.js +0 -184
- package/dist/Jsexecutor.js.map +0 -1
- package/dist/storage/operator/ArrayEqual.d.ts +0 -3
- package/dist/storage/operator/ArrayEqual.js +0 -13
- package/dist/storage/operator/ArrayEqual.js.map +0 -1
- package/dist/util/Vocabularies/core.d.ts +0 -7
- package/dist/util/Vocabularies/core.js +0 -119
- package/dist/util/Vocabularies/core.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PermissionConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Builds Deno permissions array based on options
|
|
4
|
+
* @param config - Permission configuration
|
|
5
|
+
* @returns Array of permission strings for Deno command
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildDenoPermissions(config: PermissionConfig): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Validates permission configuration
|
|
10
|
+
* @param config - Permission configuration to validate
|
|
11
|
+
* @throws Error if configuration is invalid
|
|
12
|
+
*/
|
|
13
|
+
export declare function validatePermissionConfig(config: PermissionConfig): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePermissionConfig = exports.buildDenoPermissions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Builds Deno permissions array based on options
|
|
6
|
+
* @param config - Permission configuration
|
|
7
|
+
* @returns Array of permission strings for Deno command
|
|
8
|
+
*/
|
|
9
|
+
function buildDenoPermissions(config) {
|
|
10
|
+
const permissions = [];
|
|
11
|
+
// Add network permissions if enabled
|
|
12
|
+
if (config.allowNetwork) {
|
|
13
|
+
if (config.allowedDomains.length > 0) {
|
|
14
|
+
permissions.push(`--allow-net=${config.allowedDomains.join(',')}`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
permissions.push('--allow-net');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Add env permissions if enabled
|
|
21
|
+
if (config.allowEnv) {
|
|
22
|
+
permissions.push('--allow-env');
|
|
23
|
+
}
|
|
24
|
+
// Add read permissions if enabled
|
|
25
|
+
if (config.allowRead) {
|
|
26
|
+
permissions.push('--allow-read');
|
|
27
|
+
}
|
|
28
|
+
return permissions;
|
|
29
|
+
}
|
|
30
|
+
exports.buildDenoPermissions = buildDenoPermissions;
|
|
31
|
+
/**
|
|
32
|
+
* Basic domain validation
|
|
33
|
+
* @param domain - Domain to validate
|
|
34
|
+
* @returns True if domain format is valid
|
|
35
|
+
*/
|
|
36
|
+
function isValidDomain(domain) {
|
|
37
|
+
// Basic domain validation - can be enhanced as needed
|
|
38
|
+
const domainRegex = /^[\dA-Za-z]([\dA-Za-z-]{0,61}[\dA-Za-z])?(\.[\dA-Za-z]([\dA-Za-z-]{0,61}[\dA-Za-z])?)*$/u;
|
|
39
|
+
return domainRegex.test(domain) && domain.length <= 253;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validates permission configuration
|
|
43
|
+
* @param config - Permission configuration to validate
|
|
44
|
+
* @throws Error if configuration is invalid
|
|
45
|
+
*/
|
|
46
|
+
function validatePermissionConfig(config) {
|
|
47
|
+
if (config.allowedDomains.length > 0 && !config.allowNetwork) {
|
|
48
|
+
throw new Error('allowedDomains specified but allowNetwork is false');
|
|
49
|
+
}
|
|
50
|
+
// Validate domain format
|
|
51
|
+
for (const domain of config.allowedDomains) {
|
|
52
|
+
if (!isValidDomain(domain)) {
|
|
53
|
+
throw new Error(`Invalid domain format: ${domain}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.validatePermissionConfig = validatePermissionConfig;
|
|
58
|
+
//# sourceMappingURL=PermissionBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PermissionBuilder.js","sourceRoot":"","sources":["../../src/JsExecutor/PermissionBuilder.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,MAAwB;IAC3D,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,qCAAqC;IACrC,IAAI,MAAM,CAAC,YAAY,EAAE;QACvB,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YACpC,WAAW,CAAC,IAAI,CAAC,eAAe,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SACpE;aAAM;YACL,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SACjC;KACF;IAED,iCAAiC;IACjC,IAAI,MAAM,CAAC,QAAQ,EAAE;QACnB,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KACjC;IAED,kCAAkC;IAClC,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;KAClC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAvBD,oDAuBC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,MAAc;IACnC,sDAAsD;IACtD,MAAM,WAAW,GAAG,0FAA0F,CAAC;IAC/G,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,MAAwB;IAC/D,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;QAC5D,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;IAED,yBAAyB;IACzB,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,cAAc,EAAE;QAC1C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAC;SACrD;KACF;AACH,CAAC;AAXD,4DAWC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for JSExecutor configuration
|
|
3
|
+
*/
|
|
4
|
+
export declare const EXECUTION_CONSTANTS: {
|
|
5
|
+
readonly defaultTimeout: 5000;
|
|
6
|
+
readonly defaultFunctionName: "main";
|
|
7
|
+
readonly maxOutputLength: 500;
|
|
8
|
+
readonly denoCommand: "deno";
|
|
9
|
+
readonly denoFlags: readonly ["run", "--unstable-detect-cjs", "--quiet", "--unstable-sloppy-imports"];
|
|
10
|
+
readonly processSignals: {
|
|
11
|
+
readonly term: "SIGTERM";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Default execution options
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_EXECUTION_OPTIONS: {
|
|
18
|
+
readonly timeout: 5000;
|
|
19
|
+
readonly functionName: "main";
|
|
20
|
+
readonly allowNetwork: false;
|
|
21
|
+
readonly allowedDomains: readonly [];
|
|
22
|
+
readonly allowEnv: true;
|
|
23
|
+
readonly allowRead: false;
|
|
24
|
+
readonly debugMode: false;
|
|
25
|
+
readonly retries: 0;
|
|
26
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_EXECUTION_OPTIONS = exports.EXECUTION_CONSTANTS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Constants for JSExecutor configuration
|
|
6
|
+
*/
|
|
7
|
+
exports.EXECUTION_CONSTANTS = {
|
|
8
|
+
defaultTimeout: 5000,
|
|
9
|
+
defaultFunctionName: 'main',
|
|
10
|
+
maxOutputLength: 500,
|
|
11
|
+
denoCommand: 'deno',
|
|
12
|
+
denoFlags: ['run', '--unstable-detect-cjs', '--quiet', '--unstable-sloppy-imports'],
|
|
13
|
+
processSignals: {
|
|
14
|
+
term: 'SIGTERM'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Default execution options
|
|
19
|
+
*/
|
|
20
|
+
exports.DEFAULT_EXECUTION_OPTIONS = {
|
|
21
|
+
timeout: exports.EXECUTION_CONSTANTS.defaultTimeout,
|
|
22
|
+
functionName: exports.EXECUTION_CONSTANTS.defaultFunctionName,
|
|
23
|
+
allowNetwork: false,
|
|
24
|
+
allowedDomains: [],
|
|
25
|
+
allowEnv: true,
|
|
26
|
+
allowRead: false,
|
|
27
|
+
debugMode: false,
|
|
28
|
+
retries: 0
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/JsExecutor/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,mBAAmB,GAAG;IACjC,cAAc,EAAE,IAAI;IACpB,mBAAmB,EAAE,MAAM;IAC3B,eAAe,EAAE,GAAG;IACpB,WAAW,EAAE,MAAM;IACnB,SAAS,EAAE,CAAE,KAAK,EAAE,uBAAuB,EAAE,SAAS,EAAE,2BAA2B,CAAE;IACrF,cAAc,EAAE;QACd,IAAI,EAAE,SAAS;KAChB;CACO,CAAC;AAEX;;GAEG;AACU,QAAA,yBAAyB,GAAG;IACvC,OAAO,EAAE,2BAAmB,CAAC,cAAc;IAC3C,YAAY,EAAE,2BAAmB,CAAC,mBAAmB;IACrD,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,EAAE;IAClB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ChildProcess } from 'node:child_process';
|
|
3
|
+
/**
|
|
4
|
+
* Spawns a Deno process with the given arguments
|
|
5
|
+
* @param commandArgs - Command line arguments for Deno
|
|
6
|
+
* @returns The spawned child process
|
|
7
|
+
* @throws ProcessSpawnError if the process fails to spawn
|
|
8
|
+
*/
|
|
9
|
+
export declare function spawnDenoProcess(commandArgs: string[]): ChildProcess;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spawnDenoProcess = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
/**
|
|
8
|
+
* Spawns a Deno process with the given arguments
|
|
9
|
+
* @param commandArgs - Command line arguments for Deno
|
|
10
|
+
* @returns The spawned child process
|
|
11
|
+
* @throws ProcessSpawnError if the process fails to spawn
|
|
12
|
+
*/
|
|
13
|
+
function spawnDenoProcess(commandArgs) {
|
|
14
|
+
try {
|
|
15
|
+
return (0, node_child_process_1.spawn)(constants_1.EXECUTION_CONSTANTS.denoCommand, commandArgs, {
|
|
16
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new errors_1.ProcessSpawnError(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.spawnDenoProcess = spawnDenoProcess;
|
|
24
|
+
//# sourceMappingURL=denoUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"denoUtils.js","sourceRoot":"","sources":["../../src/JsExecutor/denoUtils.ts"],"names":[],"mappings":";;;AACA,2DAA2C;AAC3C,2CAAkD;AAClD,qCAA6C;AAE7C;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,WAAqB;IACpD,IAAI;QACF,OAAO,IAAA,0BAAK,EAAC,+BAAmB,CAAC,WAAW,EAAE,WAAW,EAAE;YACzD,KAAK,EAAE,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAE;SAClC,CAAC,CAAC;KACJ;IAAC,OAAO,KAAc,EAAE;QACvB,MAAM,IAAI,0BAAiB,CAAC,KAAc,CAAC,CAAC;KAC7C;AACH,CAAC;AARD,4CAQC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for better error handling in JSExecutor
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when code execution times out
|
|
6
|
+
*/
|
|
7
|
+
export declare class ExecutionTimeoutError extends Error {
|
|
8
|
+
constructor(timeout: number);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when the Deno process fails to spawn
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProcessSpawnError extends Error {
|
|
14
|
+
constructor(originalError: Error);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when the executor output cannot be parsed
|
|
18
|
+
*/
|
|
19
|
+
export declare class OutputParsingError extends Error {
|
|
20
|
+
constructor(rawOutput: string, originalError: Error);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when code execution fails in general
|
|
24
|
+
*/
|
|
25
|
+
export declare class CodeExecutionError extends Error {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Error thrown when the JSExecutor is not initialized
|
|
30
|
+
*/
|
|
31
|
+
export declare class NotInitializedError extends Error {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error thrown when the JSExecutor is already initialized
|
|
36
|
+
*/
|
|
37
|
+
export declare class AlreadyInitializedError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom error classes for better error handling in JSExecutor
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AlreadyInitializedError = exports.NotInitializedError = exports.CodeExecutionError = exports.OutputParsingError = exports.ProcessSpawnError = exports.ExecutionTimeoutError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when code execution times out
|
|
9
|
+
*/
|
|
10
|
+
class ExecutionTimeoutError extends Error {
|
|
11
|
+
constructor(timeout) {
|
|
12
|
+
super(`Execution timed out after ${timeout}ms`);
|
|
13
|
+
this.name = 'ExecutionTimeoutError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ExecutionTimeoutError = ExecutionTimeoutError;
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when the Deno process fails to spawn
|
|
19
|
+
*/
|
|
20
|
+
class ProcessSpawnError extends Error {
|
|
21
|
+
constructor(originalError) {
|
|
22
|
+
super(`Failed to spawn Deno process: ${originalError.message}`);
|
|
23
|
+
this.name = 'ProcessSpawnError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ProcessSpawnError = ProcessSpawnError;
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when the executor output cannot be parsed
|
|
29
|
+
*/
|
|
30
|
+
class OutputParsingError extends Error {
|
|
31
|
+
constructor(rawOutput, originalError) {
|
|
32
|
+
super(`Failed to parse output: ${originalError.message}`);
|
|
33
|
+
this.name = 'OutputParsingError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.OutputParsingError = OutputParsingError;
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when code execution fails in general
|
|
39
|
+
*/
|
|
40
|
+
class CodeExecutionError extends Error {
|
|
41
|
+
constructor(message) {
|
|
42
|
+
super(`Failed to execute code: ${message}`);
|
|
43
|
+
this.name = 'CodeExecutionError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.CodeExecutionError = CodeExecutionError;
|
|
47
|
+
/**
|
|
48
|
+
* Error thrown when the JSExecutor is not initialized
|
|
49
|
+
*/
|
|
50
|
+
class NotInitializedError extends Error {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = 'NotInitializedError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.NotInitializedError = NotInitializedError;
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when the JSExecutor is already initialized
|
|
59
|
+
*/
|
|
60
|
+
class AlreadyInitializedError extends Error {
|
|
61
|
+
constructor(message) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.name = 'AlreadyInitializedError';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.AlreadyInitializedError = AlreadyInitializedError;
|
|
67
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/JsExecutor/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAmB,OAAe;QAChC,KAAK,CAAC,6BAA6B,OAAO,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC;AAED;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAmB,aAAoB;QACrC,KAAK,CAAC,iCAAiC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AALD,8CAKC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAmB,SAAiB,EAAE,aAAoB;QACxD,KAAK,CAAC,2BAA2B,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAmB,OAAe;QAChC,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AALD,0DAKC"}
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// /* eslint-disable func-style */
|
|
3
|
+
// /* eslint-disable no-console */
|
|
4
|
+
// import path from 'node:path';
|
|
5
|
+
// import { JsonRpcServer } from '../../transport/JsonRpcServer';
|
|
6
|
+
// import { StdioTransport } from '../../transport/StdioTransport';
|
|
7
|
+
// const server = new JsonRpcServer();
|
|
8
|
+
// // Register methods that the child process can call
|
|
9
|
+
// server.registerMethod('getTime', async(): Promise<{ result: string }> => {
|
|
10
|
+
// console.log('📅 Child requested current time');
|
|
11
|
+
// return {
|
|
12
|
+
// result: new Date().toISOString()
|
|
13
|
+
// };
|
|
14
|
+
// });
|
|
15
|
+
// // Handle notifications from child
|
|
16
|
+
// server.registerMethod('childNotification', async(params: { message: string; timestamp: string }): Promise<void> => {
|
|
17
|
+
// console.log('📨 Received notification from child:', params);
|
|
18
|
+
// // Notifications don't return responses
|
|
19
|
+
// });
|
|
20
|
+
// const stdioTransport = new StdioTransport(path.resolve(__dirname, './process.ts'), server);
|
|
21
|
+
// stdioTransport.setName('basic-example-parent');
|
|
22
|
+
// const main = async(): Promise<void> => {
|
|
23
|
+
// console.log('🚀 Starting parent process');
|
|
24
|
+
// await stdioTransport.initialize();
|
|
25
|
+
// console.log('✅ Child process initialized');
|
|
26
|
+
// // Example: Make some calls to the child process using the new ergonomic API
|
|
27
|
+
// try {
|
|
28
|
+
// // Test basic ping
|
|
29
|
+
// // const pingResult = await stdioTransport.request('ping');
|
|
30
|
+
// // console.log('🏓 Ping result:', pingResult);
|
|
31
|
+
// // // Test child calling back to parent
|
|
32
|
+
// const callParentResult = await stdioTransport.request('callParent');
|
|
33
|
+
// console.log('🔄 Child callback result:', callParentResult);
|
|
34
|
+
// // // Test child sending notification
|
|
35
|
+
// // const notifyResult = await stdioTransport.request('sendNotification');
|
|
36
|
+
// // console.log('📤 Notification test result:', notifyResult);
|
|
37
|
+
// // // Test execute code method
|
|
38
|
+
// // const executeResult = await stdioTransport.request('executeCode', 'console.log("Hello from executed code!")');
|
|
39
|
+
// // console.log('⚡ Execute result:', executeResult);
|
|
40
|
+
// await stdioTransport.close();
|
|
41
|
+
// } catch (error: unknown) {
|
|
42
|
+
// console.error('❌ Error testing child methods:', (error as Error).message);
|
|
43
|
+
// }
|
|
44
|
+
// };
|
|
45
|
+
// main().catch(console.error);
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/JsExecutor/examples/basic/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC,kCAAkC;AAClC,gCAAgC;AAChC,iEAAiE;AACjE,mEAAmE;AAEnE,sCAAsC;AAEtC,sDAAsD;AACtD,6EAA6E;AAC7E,oDAAoD;AACpD,aAAa;AACb,uCAAuC;AACvC,OAAO;AACP,MAAM;AAEN,qCAAqC;AACrC,uHAAuH;AACvH,iEAAiE;AACjE,4CAA4C;AAC5C,MAAM;AAEN,8FAA8F;AAC9F,kDAAkD;AAElD,2CAA2C;AAC3C,+CAA+C;AAC/C,uCAAuC;AACvC,gDAAgD;AAEhD,iFAAiF;AACjF,UAAU;AACV,yBAAyB;AACzB,kEAAkE;AAClE,qDAAqD;AAErD,8CAA8C;AAC9C,2EAA2E;AAC3E,kEAAkE;AAElE,4CAA4C;AAC5C,gFAAgF;AAChF,oEAAoE;AAEpE,qCAAqC;AACrC,wHAAwH;AACxH,0DAA0D;AAC1D,oCAAoC;AACpC,+BAA+B;AAC/B,iFAAiF;AACjF,MAAM;AACN,KAAK;AAEL,+BAA+B"}
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// /* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
+
// // @ts-nocheck
|
|
4
|
+
// import { BidirectionalStdioTransport } from '../../transport/StdioTransport.ts';
|
|
5
|
+
// // Create a single transport that handles both server and client functionality
|
|
6
|
+
// const transport = new BidirectionalStdioTransport();
|
|
7
|
+
// transport.setName('basic-example-process');
|
|
8
|
+
// // Register methods that the parent can call (server functionality)
|
|
9
|
+
// transport.registerMethod('executeCode', async(message: string): Promise<{ result: string }> => ({
|
|
10
|
+
// result: 'Hello from the process'
|
|
11
|
+
// }));
|
|
12
|
+
// transport.registerMethod('ping', async(): Promise<string> => 'pong');
|
|
13
|
+
// // Register a method that demonstrates calling back to the parent (client functionality)
|
|
14
|
+
// transport.registerMethod('callParent', async(): Promise<{ result: string }> => {
|
|
15
|
+
// try {
|
|
16
|
+
// // Call the parent's getTime method
|
|
17
|
+
// const result = await transport.request('getTime');
|
|
18
|
+
// return { result: `Parent getTime returned: ${JSON.stringify(result)}` };
|
|
19
|
+
// } catch (error: unknown) {
|
|
20
|
+
// return { result: `Error calling parent: ${(error as Error).message}` };
|
|
21
|
+
// }
|
|
22
|
+
// });
|
|
23
|
+
// // Register a method that sends notifications to parent
|
|
24
|
+
// transport.registerMethod('sendNotification', async(): Promise<{ result: string }> => {
|
|
25
|
+
// // Send a notification (no response expected)
|
|
26
|
+
// await transport.notify('childNotification', {
|
|
27
|
+
// message: 'Hello from child process',
|
|
28
|
+
// timestamp: new Date().toISOString()
|
|
29
|
+
// });
|
|
30
|
+
// return { result: 'Notification sent to parent' };
|
|
31
|
+
// });
|
|
32
|
+
// // Initialize the transport (this sets up stdio communication)
|
|
33
|
+
// await transport.initialize();
|
|
34
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../../../src/JsExecutor/examples/basic/process.ts"],"names":[],"mappings":";AAAA,yDAAyD;AAEzD,iBAAiB;AACjB,mFAAmF;AAEnF,iFAAiF;AACjF,uDAAuD;AACvD,8CAA8C;AAE9C,sEAAsE;AACtE,oGAAoG;AACpG,qCAAqC;AACrC,OAAO;AAEP,wEAAwE;AAExE,2FAA2F;AAC3F,mFAAmF;AACnF,UAAU;AACV,0CAA0C;AAC1C,yDAAyD;AACzD,+EAA+E;AAC/E,+BAA+B;AAC/B,8EAA8E;AAC9E,MAAM;AACN,MAAM;AAEN,0DAA0D;AAC1D,yFAAyF;AACzF,kDAAkD;AAClD,kDAAkD;AAClD,2CAA2C;AAC3C,0CAA0C;AAC1C,QAAQ;AACR,sDAAsD;AACtD,MAAM;AAEN,iEAAiE;AACjE,gCAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable func-style */
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const jsExecutor_1 = require("../../jsExecutor");
|
|
10
|
+
const jsExecutor = new jsExecutor_1.JSExecutor(node_path_1.default.resolve(__dirname, './process.ts'), {
|
|
11
|
+
async getTime() {
|
|
12
|
+
return new Date().toISOString();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const main = async () => {
|
|
16
|
+
await jsExecutor.initialize();
|
|
17
|
+
try {
|
|
18
|
+
const result = await jsExecutor.execute(`
|
|
19
|
+
async function main() {
|
|
20
|
+
// Using SKL accessor - this gets converted to request('getTime', ...)
|
|
21
|
+
return await SKL.getTime({}, {
|
|
22
|
+
timeout: 50000,
|
|
23
|
+
retries: 0
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Alternative: direct request call (still works)
|
|
27
|
+
// return await request('getTime', {}, {
|
|
28
|
+
// timeout: 50000,
|
|
29
|
+
// retries: 0
|
|
30
|
+
// });
|
|
31
|
+
}
|
|
32
|
+
`, {}, {
|
|
33
|
+
timeout: 50000,
|
|
34
|
+
functionName: 'main',
|
|
35
|
+
retries: 0
|
|
36
|
+
});
|
|
37
|
+
console.log({ result });
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error({ error });
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await jsExecutor.shutdown();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
main().catch(console.error);
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/JsExecutor/examples/jsExecutor/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,+BAA+B;;;;;AAE/B,0DAA6B;AAC7B,iDAA8C;AAE9C,MAAM,UAAU,GAAG,IAAI,uBAAU,CAAC,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE;IACzE,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,KAAK,IAAkB,EAAE;IACpC,MAAM,UAAU,CAAC,UAAU,EAAE,CAAC;IAE9B,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CACrC;;;;;;;;;;;;;;CAcL,EACK,EAAE,EACF;YACE,OAAO,EAAE,KAAK;YACd,YAAY,EAAE,MAAM;YACpB,OAAO,EAAE,CAAC;SACX,CACF,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1B,oEAAoE;KACnE;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;KAC1B;YAAS;QACR,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;KAC7B;AACH,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
5
|
+
/* eslint-disable prefer-arrow-callback */
|
|
6
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
7
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
const ChildStdioTransport_ts_1 = require("../../transport/stdio/ChildStdioTransport.ts");
|
|
10
|
+
// Create a single transport that handles both server and client functionality
|
|
11
|
+
const transport = new ChildStdioTransport_ts_1.ChildStdioTransport();
|
|
12
|
+
transport.setName('jsExecutor-example-process');
|
|
13
|
+
// Register methods that the parent can call (server functionality)
|
|
14
|
+
transport.registerMethod('executeCode', async (message) => {
|
|
15
|
+
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
16
|
+
const executeCode = new AsyncFunction('args', 'console', 'request', 'SKL', `
|
|
17
|
+
${message.code}
|
|
18
|
+
try {
|
|
19
|
+
if (typeof ${message.functionName} === 'function') {
|
|
20
|
+
return await ${message.functionName}(args);
|
|
21
|
+
}
|
|
22
|
+
throw new Error('Function name is not defined');
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
`);
|
|
27
|
+
// Const sklEngine = new SKLEngine({
|
|
28
|
+
// skdsEndpointUrl: 'http://localhost:3000'
|
|
29
|
+
// });
|
|
30
|
+
// Create SKL proxy that converts method calls to request calls
|
|
31
|
+
const SKL = new Proxy({}, {
|
|
32
|
+
get(target, prop) {
|
|
33
|
+
if (typeof prop === 'string') {
|
|
34
|
+
return async (...args) => {
|
|
35
|
+
// Convert method call to request call
|
|
36
|
+
// SKL.getTime() becomes request('getTime', {}, options)
|
|
37
|
+
const [params = {}, options = {}] = args;
|
|
38
|
+
return await transport.request(prop, params, options);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const result = await executeCode(message.args, console, transport.request.bind(transport), SKL);
|
|
44
|
+
return { result };
|
|
45
|
+
});
|
|
46
|
+
transport.registerMethod('ping', async () => 'pong');
|
|
47
|
+
// Register a method that demonstrates calling back to the parent (client functionality)
|
|
48
|
+
// transport.registerMethod('callParent', async(): Promise<{ result: string }> => {
|
|
49
|
+
// try {
|
|
50
|
+
// // Call the parent's getTime method
|
|
51
|
+
// const result = await transport.request('getTime');
|
|
52
|
+
// return { result: `Parent getTime returned: ${JSON.stringify(result)}` };
|
|
53
|
+
// } catch (error: unknown) {
|
|
54
|
+
// return { result: `Error calling parent: ${(error as Error).message}` };
|
|
55
|
+
// }
|
|
56
|
+
// });
|
|
57
|
+
// Initialize the transport (this sets up stdio communication)
|
|
58
|
+
await transport.initialize();
|
|
59
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../../../src/JsExecutor/examples/jsExecutor/process.ts"],"names":[],"mappings":";;AAAA,yDAAyD;AACzD,yDAAyD;AACzD,0CAA0C;AAC1C,qEAAqE;AACrE,sDAAsD;AACtD,cAAc;AACd,yFAAmF;AAQnF,8EAA8E;AAC9E,MAAM,SAAS,GAAG,IAAI,4CAAmB,EAAE,CAAC;AAC5C,SAAS,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAEhD,mEAAmE;AACnE,SAAS,CAAC,cAAc,CACtB,aAAa,EACb,KAAK,EAAC,OAA2B,EAA+B,EAAE;IAChE,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,eAAa,CAAC,CAAC,CAAC,WAAW,CAAC;IAC7E,MAAM,WAAW,GAAG,IAAI,aAAa,CACnC,MAAM,EACN,SAAS,EACT,SAAS,EACT,KAAK,EACL;UACI,OAAO,CAAC,IAAI;;uBAEC,OAAO,CAAC,YAAY;2BAChB,OAAO,CAAC,YAAY;;;;;;OAMxC,CACF,CAAC;IAEF,oCAAoC;IACpC,6CAA6C;IAC7C,MAAM;IAEN,+DAA+D;IAC/D,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;QACxB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC5B,OAAO,KAAK,EAAC,GAAG,IAAW,EAAE,EAAE;oBAC7B,sCAAsC;oBACtC,wDAAwD;oBACxD,MAAM,CAAE,MAAM,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,CAAE,GAAG,IAAI,CAAC;oBAC3C,OAAO,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBACxD,CAAC,CAAC;aACH;QACH,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;IAChG,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CACF,CAAC;AAEF,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,IAAoB,EAAE,CAAC,MAAM,CAAC,CAAC;AAErE,wFAAwF;AACxF,mFAAmF;AACnF,UAAU;AACV,0CAA0C;AAC1C,yDAAyD;AACzD,+EAA+E;AAC/E,+BAA+B;AAC/B,8EAA8E;AAC9E,MAAM;AACN,MAAM;AAEN,8DAA8D;AAC9D,MAAM,SAAS,CAAC,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DEFAULT_EXECUTION_OPTIONS, EXECUTION_CONSTANTS } from './constants';
|
|
2
|
+
export { CodeExecutionError, ExecutionTimeoutError, OutputParsingError, ProcessSpawnError } from './errors';
|
|
3
|
+
export { JSExecutor } from './jsExecutor';
|
|
4
|
+
export { buildDenoPermissions, validatePermissionConfig } from './PermissionBuilder';
|
|
5
|
+
export * from './transport';
|
|
6
|
+
export type { ExecutionOptions, ExecutionResult, ExecutorInput, ExecutorOutput, PermissionConfig, ProcessCommunicationData } from './types';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.validatePermissionConfig = exports.buildDenoPermissions = exports.JSExecutor = exports.ProcessSpawnError = exports.OutputParsingError = exports.ExecutionTimeoutError = exports.CodeExecutionError = exports.EXECUTION_CONSTANTS = exports.DEFAULT_EXECUTION_OPTIONS = void 0;
|
|
18
|
+
// Main executor class
|
|
19
|
+
// Constants
|
|
20
|
+
var constants_1 = require("./constants");
|
|
21
|
+
Object.defineProperty(exports, "DEFAULT_EXECUTION_OPTIONS", { enumerable: true, get: function () { return constants_1.DEFAULT_EXECUTION_OPTIONS; } });
|
|
22
|
+
Object.defineProperty(exports, "EXECUTION_CONSTANTS", { enumerable: true, get: function () { return constants_1.EXECUTION_CONSTANTS; } });
|
|
23
|
+
// Error classes
|
|
24
|
+
var errors_1 = require("./errors");
|
|
25
|
+
Object.defineProperty(exports, "CodeExecutionError", { enumerable: true, get: function () { return errors_1.CodeExecutionError; } });
|
|
26
|
+
Object.defineProperty(exports, "ExecutionTimeoutError", { enumerable: true, get: function () { return errors_1.ExecutionTimeoutError; } });
|
|
27
|
+
Object.defineProperty(exports, "OutputParsingError", { enumerable: true, get: function () { return errors_1.OutputParsingError; } });
|
|
28
|
+
Object.defineProperty(exports, "ProcessSpawnError", { enumerable: true, get: function () { return errors_1.ProcessSpawnError; } });
|
|
29
|
+
var jsExecutor_1 = require("./jsExecutor");
|
|
30
|
+
Object.defineProperty(exports, "JSExecutor", { enumerable: true, get: function () { return jsExecutor_1.JSExecutor; } });
|
|
31
|
+
// Utility functions (for advanced usage)
|
|
32
|
+
var PermissionBuilder_1 = require("./PermissionBuilder");
|
|
33
|
+
Object.defineProperty(exports, "buildDenoPermissions", { enumerable: true, get: function () { return PermissionBuilder_1.buildDenoPermissions; } });
|
|
34
|
+
Object.defineProperty(exports, "validatePermissionConfig", { enumerable: true, get: function () { return PermissionBuilder_1.validatePermissionConfig; } });
|
|
35
|
+
__exportStar(require("./transport"), exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/JsExecutor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sBAAsB;AACtB,YAAY;AACZ,yCAA6E;AAApE,sHAAA,yBAAyB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AACvD,gBAAgB;AAChB,mCAA4G;AAAnG,4GAAA,kBAAkB,OAAA;AAAE,+GAAA,qBAAqB,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AACzF,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,yCAAyC;AACzC,yDAAqF;AAA5E,yHAAA,oBAAoB,OAAA;AAAE,6HAAA,wBAAwB,OAAA;AACvD,8CAA4B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { TransportConfig } from './transport';
|
|
2
|
+
import type { ExecutionOptions, IShutdownOptions } from './types';
|
|
3
|
+
export declare type IJSCallbacks = Record<string, (...args: any[]) => any>;
|
|
4
|
+
/**
|
|
5
|
+
* JSExecutor V2 with enhanced abort control for immediate shutdown
|
|
6
|
+
*
|
|
7
|
+
* @example Writing abort-aware callbacks:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const jsExecutor = new JSExecutorV2(scriptPath, {
|
|
10
|
+
* async myCallback(): Promise<string> {
|
|
11
|
+
* return new Promise((resolve, reject) => {
|
|
12
|
+
* const timeoutId = setTimeout(() => resolve('done'), 5000);
|
|
13
|
+
*
|
|
14
|
+
* // Listen to the global abort signal to clean up resources
|
|
15
|
+
* const abortSignal = JSExecutorV2.getGlobalAbortSignal();
|
|
16
|
+
* const onAbort = () => {
|
|
17
|
+
* clearTimeout(timeoutId);
|
|
18
|
+
* reject(new Error('Operation aborted'));
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* if (abortSignal.aborted) {
|
|
22
|
+
* onAbort();
|
|
23
|
+
* return;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* abortSignal.addEventListener('abort', onAbort);
|
|
27
|
+
* });
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class JSExecutor {
|
|
33
|
+
private readonly executorScriptPath;
|
|
34
|
+
private readonly callbacks;
|
|
35
|
+
private isInitialized;
|
|
36
|
+
private server?;
|
|
37
|
+
private transport?;
|
|
38
|
+
private readonly abortController;
|
|
39
|
+
private static readonly globalAbortController;
|
|
40
|
+
private shutdownTimeout?;
|
|
41
|
+
constructor(executorScriptPath: string, callbacks: IJSCallbacks);
|
|
42
|
+
/**
|
|
43
|
+
* Static method to check if any JSExecutor instance is being shut down
|
|
44
|
+
* Callbacks can use this to check if they should abort their operations
|
|
45
|
+
*/
|
|
46
|
+
static isShuttingDown(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Get the global abort signal that callbacks can listen to
|
|
49
|
+
* This allows callbacks to immediately abort when any JSExecutor shuts down
|
|
50
|
+
*/
|
|
51
|
+
static getGlobalAbortSignal(): AbortSignal;
|
|
52
|
+
initialize(config?: TransportConfig, executionOptions?: ExecutionOptions): Promise<void>;
|
|
53
|
+
shutdown(options?: IShutdownOptions): Promise<void>;
|
|
54
|
+
private shutdownCore;
|
|
55
|
+
private rpcComplaintCallback;
|
|
56
|
+
/**
|
|
57
|
+
* Wrap a callback with abort functionality
|
|
58
|
+
* The callback will be automatically aborted if JSExecutor is shut down
|
|
59
|
+
*/
|
|
60
|
+
private wrapCallbackWithAbort;
|
|
61
|
+
execute(code: string, args: Record<string, any>, executionOptions: ExecutionOptions): Promise<any>;
|
|
62
|
+
/**
|
|
63
|
+
* Legacy method for backward compatibility
|
|
64
|
+
* @deprecated Use execute() instead
|
|
65
|
+
*/
|
|
66
|
+
call(methodName: string, ...args: any[]): Promise<any>;
|
|
67
|
+
}
|