@optimizely/ocp-local-env 1.0.0-beta.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/README.md +165 -0
- package/dist/package.json +104 -0
- package/dist/public/bundle.da978bb5437cd82e6d37.js +3 -0
- package/dist/public/bundle.da978bb5437cd82e6d37.js.LICENSE.txt +49 -0
- package/dist/public/bundle.da978bb5437cd82e6d37.js.map +1 -0
- package/dist/public/index.html +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +88 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/executor/FunctionExecutor.d.ts +56 -0
- package/dist/src/executor/FunctionExecutor.js +175 -0
- package/dist/src/executor/FunctionExecutor.js.map +1 -0
- package/dist/src/executor/JobExecutor.d.ts +60 -0
- package/dist/src/executor/JobExecutor.js +203 -0
- package/dist/src/executor/JobExecutor.js.map +1 -0
- package/dist/src/executor/LifecycleExecutor.d.ts +45 -0
- package/dist/src/executor/LifecycleExecutor.js +153 -0
- package/dist/src/executor/LifecycleExecutor.js.map +1 -0
- package/dist/src/executor/watcher.d.ts +63 -0
- package/dist/src/executor/watcher.js +213 -0
- package/dist/src/executor/watcher.js.map +1 -0
- package/dist/src/functions/hello.d.ts +4 -0
- package/dist/src/functions/hello.js +8 -0
- package/dist/src/functions/hello.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jobs/dailyJob.d.ts +4 -0
- package/dist/src/jobs/dailyJob.js +8 -0
- package/dist/src/jobs/dailyJob.js.map +1 -0
- package/dist/src/local_engine/LocalNotifier.d.ts +10 -0
- package/dist/src/local_engine/LocalNotifier.js +26 -0
- package/dist/src/local_engine/LocalNotifier.js.map +1 -0
- package/dist/src/local_engine/local-engine-child-base.d.ts +79 -0
- package/dist/src/local_engine/local-engine-child-base.js +304 -0
- package/dist/src/local_engine/local-engine-child-base.js.map +1 -0
- package/dist/src/local_engine/local-engine-client.d.ts +80 -0
- package/dist/src/local_engine/local-engine-client.js +333 -0
- package/dist/src/local_engine/local-engine-client.js.map +1 -0
- package/dist/src/local_engine/local-engine-types.d.ts +132 -0
- package/dist/src/local_engine/local-engine-types.js +6 -0
- package/dist/src/local_engine/local-engine-types.js.map +1 -0
- package/dist/src/local_engine/local-engine-unified.d.ts +40 -0
- package/dist/src/local_engine/local-engine-unified.js +406 -0
- package/dist/src/local_engine/local-engine-unified.js.map +1 -0
- package/dist/src/local_engine/local-engine-utils.d.ts +70 -0
- package/dist/src/local_engine/local-engine-utils.js +192 -0
- package/dist/src/local_engine/local-engine-utils.js.map +1 -0
- package/dist/src/local_engine/localSDKConfig.d.ts +30 -0
- package/dist/src/local_engine/localSDKConfig.js +392 -0
- package/dist/src/local_engine/localSDKConfig.js.map +1 -0
- package/dist/src/local_engine/storage/LocalConfigStore.d.ts +56 -0
- package/dist/src/local_engine/storage/LocalConfigStore.js +129 -0
- package/dist/src/local_engine/storage/LocalConfigStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalJobStore.d.ts +110 -0
- package/dist/src/local_engine/storage/LocalJobStore.js +239 -0
- package/dist/src/local_engine/storage/LocalJobStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalKVStore.d.ts +105 -0
- package/dist/src/local_engine/storage/LocalKVStore.js +1002 -0
- package/dist/src/local_engine/storage/LocalKVStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.d.ts +27 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.js +125 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.d.ts +114 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.js +319 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.d.ts +161 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.js +417 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.js.map +1 -0
- package/dist/src/local_engine/storage/NumberSet.d.ts +21 -0
- package/dist/src/local_engine/storage/NumberSet.js +32 -0
- package/dist/src/local_engine/storage/NumberSet.js.map +1 -0
- package/dist/src/local_engine/storage/StringSet.d.ts +21 -0
- package/dist/src/local_engine/storage/StringSet.js +32 -0
- package/dist/src/local_engine/storage/StringSet.js.map +1 -0
- package/dist/src/local_engine/types.d.ts +52 -0
- package/dist/src/local_engine/types.js +6 -0
- package/dist/src/local_engine/types.js.map +1 -0
- package/dist/src/local_engine/utils.d.ts +31 -0
- package/dist/src/local_engine/utils.js +126 -0
- package/dist/src/local_engine/utils.js.map +1 -0
- package/dist/src/logging/LogManager.d.ts +89 -0
- package/dist/src/logging/LogManager.js +237 -0
- package/dist/src/logging/LogManager.js.map +1 -0
- package/dist/src/server/api/functions.d.ts +7 -0
- package/dist/src/server/api/functions.js +80 -0
- package/dist/src/server/api/functions.js.map +1 -0
- package/dist/src/server/api/jobs.d.ts +8 -0
- package/dist/src/server/api/jobs.js +242 -0
- package/dist/src/server/api/jobs.js.map +1 -0
- package/dist/src/server/api/lifecycle.d.ts +6 -0
- package/dist/src/server/api/lifecycle.js +73 -0
- package/dist/src/server/api/lifecycle.js.map +1 -0
- package/dist/src/server/api/settings.d.ts +6 -0
- package/dist/src/server/api/settings.js +117 -0
- package/dist/src/server/api/settings.js.map +1 -0
- package/dist/src/server/api/stores.d.ts +2 -0
- package/dist/src/server/api/stores.js +341 -0
- package/dist/src/server/api/stores.js.map +1 -0
- package/dist/src/server/api/v1.d.ts +10 -0
- package/dist/src/server/api/v1.js +711 -0
- package/dist/src/server/api/v1.js.map +1 -0
- package/dist/src/server/api.d.ts +8 -0
- package/dist/src/server/api.js +154 -0
- package/dist/src/server/api.js.map +1 -0
- package/dist/src/server/app-discovery.d.ts +5 -0
- package/dist/src/server/app-discovery.js +81 -0
- package/dist/src/server/app-discovery.js.map +1 -0
- package/dist/src/server/config.d.ts +21 -0
- package/dist/src/server/config.js +100 -0
- package/dist/src/server/config.js.map +1 -0
- package/dist/src/server/websocket.d.ts +0 -0
- package/dist/src/server/websocket.js +2 -0
- package/dist/src/server/websocket.js.map +1 -0
- package/dist/src/server.d.ts +2 -0
- package/dist/src/server.js +546 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/types/app.d.ts +155 -0
- package/dist/src/types/app.js +24 -0
- package/dist/src/types/app.js.map +1 -0
- package/dist/src/types/kvstore.d.ts +320 -0
- package/dist/src/types/kvstore.js +5 -0
- package/dist/src/types/kvstore.js.map +1 -0
- package/dist/src/ui/components/App.d.ts +6 -0
- package/dist/src/ui/components/App.js +255 -0
- package/dist/src/ui/components/App.js.map +1 -0
- package/dist/src/ui/components/FunctionsView.d.ts +6 -0
- package/dist/src/ui/components/FunctionsView.js +217 -0
- package/dist/src/ui/components/FunctionsView.js.map +1 -0
- package/dist/src/ui/components/JobsView.d.ts +6 -0
- package/dist/src/ui/components/JobsView.js +257 -0
- package/dist/src/ui/components/JobsView.js.map +1 -0
- package/dist/src/ui/components/KVStoreViewer.d.ts +11 -0
- package/dist/src/ui/components/KVStoreViewer.js +168 -0
- package/dist/src/ui/components/KVStoreViewer.js.map +1 -0
- package/dist/src/ui/components/NotificationViewer.d.ts +16 -0
- package/dist/src/ui/components/NotificationViewer.js +69 -0
- package/dist/src/ui/components/NotificationViewer.js.map +1 -0
- package/dist/src/ui/components/SecretsStoreViewer.d.ts +11 -0
- package/dist/src/ui/components/SecretsStoreViewer.js +179 -0
- package/dist/src/ui/components/SecretsStoreViewer.js.map +1 -0
- package/dist/src/ui/components/SettingsStoreViewer.d.ts +24 -0
- package/dist/src/ui/components/SettingsStoreViewer.js +132 -0
- package/dist/src/ui/components/SettingsStoreViewer.js.map +1 -0
- package/dist/src/ui/components/StoreViewer.d.ts +16 -0
- package/dist/src/ui/components/StoreViewer.js +86 -0
- package/dist/src/ui/components/StoreViewer.js.map +1 -0
- package/dist/src/ui/components/TabbedConsole.d.ts +15 -0
- package/dist/src/ui/components/TabbedConsole.js +93 -0
- package/dist/src/ui/components/TabbedConsole.js.map +1 -0
- package/dist/src/ui/components/common/DataTree.d.ts +15 -0
- package/dist/src/ui/components/common/DataTree.js +95 -0
- package/dist/src/ui/components/common/DataTree.js.map +1 -0
- package/dist/src/ui/components/common/EyeIcon.d.ts +11 -0
- package/dist/src/ui/components/common/EyeIcon.js +11 -0
- package/dist/src/ui/components/common/EyeIcon.js.map +1 -0
- package/dist/src/ui/index.d.ts +1 -0
- package/dist/src/ui/index.js +20 -0
- package/dist/src/ui/index.js.map +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>OCP Local Testing Tool</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"><script defer="defer" src="bundle.da978bb5437cd82e6d37.js"></script></head><body><div id="root"></div></body></html>
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const server_1 = require("./server");
|
|
6
|
+
const package_json_1 = require("../package.json");
|
|
7
|
+
// Create the command line interface
|
|
8
|
+
const program = new commander_1.Command();
|
|
9
|
+
program
|
|
10
|
+
.name('ocp-local-env')
|
|
11
|
+
.description('Local testing environment for Optimizely Connect Platform (OCP) applications')
|
|
12
|
+
.version(package_json_1.version)
|
|
13
|
+
.option("-p, --port <port>", "Port to run the server on", "3000")
|
|
14
|
+
.option("-c, --config <path>", "Path to custom config file")
|
|
15
|
+
.option("--path <path>", "Path to the OCP app root directory")
|
|
16
|
+
.option("-v, --verbose", "Enable verbose logging")
|
|
17
|
+
.option("--no-open", "Don't automatically open browser");
|
|
18
|
+
program
|
|
19
|
+
.command("start")
|
|
20
|
+
.description("Start the local testing environment")
|
|
21
|
+
.option("-p, --port <port>", "Port to run the server on", "3000")
|
|
22
|
+
.option("-c, --config <path>", "Path to custom config file")
|
|
23
|
+
.option("--path <path>", "Path to the OCP app root directory")
|
|
24
|
+
.option("-v, --verbose", "Enable verbose logging")
|
|
25
|
+
.option("--no-open", "Don't automatically open browser")
|
|
26
|
+
.action(async (options) => {
|
|
27
|
+
try {
|
|
28
|
+
process.env.OCP_LOCAL_PORT = options.port;
|
|
29
|
+
process.env.OCP_LOCAL_CONFIG_PATH = options.config;
|
|
30
|
+
process.env.OCP_LOCAL_VERBOSE = options.verbose ? "true" : "false";
|
|
31
|
+
process.env.OCP_LOCAL_OPEN_BROWSER = options.open ? "true" : "false";
|
|
32
|
+
// Set the app root directory if provided
|
|
33
|
+
if (options.path) {
|
|
34
|
+
process.env.APP_ROOT_DIR = options.path;
|
|
35
|
+
}
|
|
36
|
+
await (0, server_1.startServer)();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error("Failed to start server:", error);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
program
|
|
44
|
+
.command('create')
|
|
45
|
+
.description('Create a new OCP app from a template')
|
|
46
|
+
.argument('<name>', 'Name of the app to create')
|
|
47
|
+
.option('-t, --template <template>', 'Template to use', 'basic')
|
|
48
|
+
.action((name, options) => {
|
|
49
|
+
console.log(`Creating new OCP app: ${name} (using template: ${options.template})`);
|
|
50
|
+
console.log('This feature is not yet implemented.');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
program
|
|
54
|
+
.command('validate')
|
|
55
|
+
.description('Validate an existing OCP app')
|
|
56
|
+
.option('-p, --path <path>', 'Path to the app directory', '.')
|
|
57
|
+
.action((options) => {
|
|
58
|
+
console.log(`Validating OCP app in: ${options.path}`);
|
|
59
|
+
console.log('This feature is not yet implemented.');
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
62
|
+
program
|
|
63
|
+
.command('help')
|
|
64
|
+
.description('Display help information')
|
|
65
|
+
.action(() => {
|
|
66
|
+
program.help();
|
|
67
|
+
});
|
|
68
|
+
// Default action when no command is provided
|
|
69
|
+
program.action(async (options) => {
|
|
70
|
+
try {
|
|
71
|
+
process.env.OCP_LOCAL_PORT = options.port;
|
|
72
|
+
process.env.OCP_LOCAL_CONFIG_PATH = options.config;
|
|
73
|
+
process.env.OCP_LOCAL_VERBOSE = options.verbose ? "true" : "false";
|
|
74
|
+
process.env.OCP_LOCAL_OPEN_BROWSER = options.open ? "true" : "false";
|
|
75
|
+
// Set the app root directory if provided
|
|
76
|
+
if (options.path) {
|
|
77
|
+
process.env.APP_ROOT_DIR = options.path;
|
|
78
|
+
}
|
|
79
|
+
await (0, server_1.startServer)();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error("Failed to start server:", error);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Parse command line arguments
|
|
87
|
+
program.parse(process.argv);
|
|
88
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,qCAAuC;AACvC,kDAA0C;AAE1C,oCAAoC;AACpC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,eAAe,CAAC;KACrB,WAAW,CAAC,8EAA8E,CAAC;KAC3F,OAAO,CAAC,sBAAO,CAAC;KAChB,MAAM,CAAC,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,CAAC;KAChE,MAAM,CAAC,qBAAqB,EAAE,4BAA4B,CAAC;KAC3D,MAAM,CAAC,eAAe,EAAE,oCAAoC,CAAC;KAC7D,MAAM,CAAC,eAAe,EAAE,wBAAwB,CAAC;KACjD,MAAM,CAAC,WAAW,EAAE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AAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAErE,yCAAyC;QACzC,IAAI,OAAO,CAAC,IAAI,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;SACzC;QAED,MAAM,IAAA,oBAAW,GAAE,CAAC;KACrB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAC,CAAC;AAEH,+BAA+B;AAC/B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { App } from '../types/app';
|
|
2
|
+
import { LocalSettingsStore } from '../local_engine/storage/LocalSettingsStore';
|
|
3
|
+
/**
|
|
4
|
+
* Function execution request data
|
|
5
|
+
*/
|
|
6
|
+
export interface FunctionExecutionRequest {
|
|
7
|
+
functionId: string;
|
|
8
|
+
method: string;
|
|
9
|
+
fullpath: string;
|
|
10
|
+
path: string;
|
|
11
|
+
params: Record<string, any>;
|
|
12
|
+
headers: [string, string][];
|
|
13
|
+
body: any;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Function execution response
|
|
17
|
+
*/
|
|
18
|
+
export interface FunctionExecutionResponse {
|
|
19
|
+
success: boolean;
|
|
20
|
+
status?: number;
|
|
21
|
+
headers?: [string, string][];
|
|
22
|
+
body?: any;
|
|
23
|
+
logs: string[];
|
|
24
|
+
error?: {
|
|
25
|
+
message: string;
|
|
26
|
+
stack?: string;
|
|
27
|
+
};
|
|
28
|
+
executionTime: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Executes functions of an OCP app in isolated processes
|
|
32
|
+
*/
|
|
33
|
+
export declare class FunctionExecutor {
|
|
34
|
+
private appDir;
|
|
35
|
+
private app;
|
|
36
|
+
private settingsStore;
|
|
37
|
+
private configStore;
|
|
38
|
+
private localEngineClient;
|
|
39
|
+
constructor(appDir: string, app: App, settingsStore: LocalSettingsStore, configStore: any);
|
|
40
|
+
/**
|
|
41
|
+
* Execute a function with the given request data
|
|
42
|
+
*/
|
|
43
|
+
executeFunction(request: FunctionExecutionRequest): Promise<FunctionExecutionResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the path to the built function file
|
|
46
|
+
*/
|
|
47
|
+
private getFunctionPath;
|
|
48
|
+
/**
|
|
49
|
+
* Execute the function script using IPC
|
|
50
|
+
*/
|
|
51
|
+
private executeFunctionScript;
|
|
52
|
+
/**
|
|
53
|
+
* Cleanup IPC connections when executor is destroyed
|
|
54
|
+
*/
|
|
55
|
+
cleanup(): Promise<void>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FunctionExecutor = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const LogManager_1 = require("../logging/LogManager");
|
|
9
|
+
const local_engine_client_1 = require("../local_engine/local-engine-client");
|
|
10
|
+
/**
|
|
11
|
+
* Executes functions of an OCP app in isolated processes
|
|
12
|
+
*/
|
|
13
|
+
class FunctionExecutor {
|
|
14
|
+
constructor(appDir, app, settingsStore, configStore) {
|
|
15
|
+
this.appDir = appDir;
|
|
16
|
+
this.app = app;
|
|
17
|
+
this.settingsStore = settingsStore;
|
|
18
|
+
this.configStore = configStore;
|
|
19
|
+
this.localEngineClient = new local_engine_client_1.LocalEngineClient();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute a function with the given request data
|
|
23
|
+
*/
|
|
24
|
+
async executeFunction(request) {
|
|
25
|
+
const logManager = LogManager_1.LogManager.getInstance();
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
const logs = [];
|
|
28
|
+
// Log function execution start
|
|
29
|
+
logManager.logFunctionExecution(request.functionId, 'started', {
|
|
30
|
+
method: request.method,
|
|
31
|
+
path: request.path
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
// Validate function exists
|
|
35
|
+
const functions = this.app.manifest.functions || {};
|
|
36
|
+
if (!functions[request.functionId]) {
|
|
37
|
+
throw new Error(`Function '${request.functionId}' not found in app manifest`);
|
|
38
|
+
}
|
|
39
|
+
const functionDef = functions[request.functionId];
|
|
40
|
+
// Check if built function file exists
|
|
41
|
+
const functionPath = this.getFunctionPath(functionDef.entry_point);
|
|
42
|
+
// Execute the function script
|
|
43
|
+
const executionResult = await this.executeFunctionScript(request, functionPath);
|
|
44
|
+
const executionTime = Date.now() - startTime;
|
|
45
|
+
if (executionResult.success) {
|
|
46
|
+
logs.push(`Function ${request.functionId} execution started`);
|
|
47
|
+
logs.push(...executionResult.logs);
|
|
48
|
+
logs.push(`Function ${request.functionId} execution completed successfully`);
|
|
49
|
+
// Log function execution success
|
|
50
|
+
logManager.logFunctionExecution(request.functionId, 'success', {
|
|
51
|
+
executionTime,
|
|
52
|
+
status: executionResult.status
|
|
53
|
+
});
|
|
54
|
+
// Log function output to centralized logging
|
|
55
|
+
logManager.logFunctionOutput(request.functionId, executionResult.logs.join('\n'));
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
status: executionResult.status,
|
|
59
|
+
headers: executionResult.headers,
|
|
60
|
+
body: executionResult.body,
|
|
61
|
+
logs,
|
|
62
|
+
executionTime,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
logs.push(`Function ${request.functionId} execution started`);
|
|
67
|
+
logs.push(...executionResult.logs);
|
|
68
|
+
logs.push(`Function ${request.functionId} execution failed: ${executionResult.error}`);
|
|
69
|
+
// Log function execution error
|
|
70
|
+
logManager.logFunctionExecution(request.functionId, 'error', {
|
|
71
|
+
executionTime,
|
|
72
|
+
error: executionResult.error
|
|
73
|
+
});
|
|
74
|
+
// Log function output to centralized logging
|
|
75
|
+
logManager.logFunctionOutput(request.functionId, executionResult.logs.join('\n'));
|
|
76
|
+
if (executionResult.error) {
|
|
77
|
+
logManager.logFunctionOutput(request.functionId, executionResult.error, true);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
logs,
|
|
82
|
+
error: {
|
|
83
|
+
message: executionResult.error || "Function execution failed",
|
|
84
|
+
stack: executionResult.stack,
|
|
85
|
+
},
|
|
86
|
+
executionTime,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const executionTime = Date.now() - startTime;
|
|
92
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
|
+
logs.push(`Function ${request.functionId} execution started`);
|
|
94
|
+
logs.push(`Error executing ${request.functionId}: ${errorMessage}`);
|
|
95
|
+
// Log function execution error
|
|
96
|
+
logManager.logFunctionExecution(request.functionId, 'error', {
|
|
97
|
+
executionTime,
|
|
98
|
+
error: errorMessage,
|
|
99
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
100
|
+
});
|
|
101
|
+
// Log error to centralized logging
|
|
102
|
+
logManager.logFunctionOutput(request.functionId, errorMessage, true);
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
logs,
|
|
106
|
+
error: {
|
|
107
|
+
message: errorMessage,
|
|
108
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
109
|
+
},
|
|
110
|
+
executionTime,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the path to the built function file
|
|
116
|
+
*/
|
|
117
|
+
getFunctionPath(entryPoint) {
|
|
118
|
+
// Try different possible locations for the built function
|
|
119
|
+
const possiblePaths = [
|
|
120
|
+
path_1.default.join(this.appDir, "dist", "functions", `${entryPoint}.js`),
|
|
121
|
+
path_1.default.join(this.appDir, "dist", "src", "functions", `${entryPoint}.js`),
|
|
122
|
+
path_1.default.join(this.appDir, "dist", `${entryPoint}.js`),
|
|
123
|
+
];
|
|
124
|
+
return possiblePaths[0]; // For now, use the first path - will validate existence in wrapper script
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Execute the function script using IPC
|
|
128
|
+
*/
|
|
129
|
+
async executeFunctionScript(request, _scriptPath) {
|
|
130
|
+
try {
|
|
131
|
+
// Convert request to IPC format
|
|
132
|
+
const ipcRequest = {
|
|
133
|
+
functionId: request.functionId,
|
|
134
|
+
method: request.method,
|
|
135
|
+
fullpath: request.fullpath,
|
|
136
|
+
path: request.path,
|
|
137
|
+
params: request.params,
|
|
138
|
+
headers: request.headers,
|
|
139
|
+
body: request.body
|
|
140
|
+
};
|
|
141
|
+
// Prepare app config for IPC
|
|
142
|
+
const appConfig = {
|
|
143
|
+
manifest: this.app.manifest,
|
|
144
|
+
path: this.appDir,
|
|
145
|
+
isBuilt: true,
|
|
146
|
+
isValid: true
|
|
147
|
+
};
|
|
148
|
+
// Execute via IPC
|
|
149
|
+
const result = await this.localEngineClient.executeFunction(ipcRequest, appConfig, this.appDir);
|
|
150
|
+
return {
|
|
151
|
+
success: result.success || true,
|
|
152
|
+
status: result.status,
|
|
153
|
+
headers: result.headers,
|
|
154
|
+
body: result.body,
|
|
155
|
+
logs: [] // IPC handles logging separately
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
logs: [],
|
|
162
|
+
error: error.message,
|
|
163
|
+
stack: error.stack
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Cleanup IPC connections when executor is destroyed
|
|
169
|
+
*/
|
|
170
|
+
async cleanup() {
|
|
171
|
+
await this.localEngineClient.closeAllConnections();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.FunctionExecutor = FunctionExecutor;
|
|
175
|
+
//# sourceMappingURL=FunctionExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FunctionExecutor.js","sourceRoot":"","sources":["../../../src/executor/FunctionExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAGxB,sDAAmD;AACnD,6EAAwE;AAiCxE;;GAEG;AACH,MAAa,gBAAgB;IAO3B,YAAY,MAAc,EAAE,GAAQ,EAAE,aAAiC,EAAE,WAAgB;QACvF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,iBAAiB,GAAG,IAAI,uCAAiB,EAAE,CAAC;IACnD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,eAAe,CAAC,OAAiC;QAC5D,MAAM,UAAU,GAAG,uBAAU,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAa,EAAE,CAAC;QAE1B,+BAA+B;QAC/B,UAAU,CAAC,oBAAoB,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE;YAC7D,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAC,CAAC;QAEH,IAAI;YACF,2BAA2B;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC;YACpD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,aAAa,OAAO,CAAC,UA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,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB,CAAC;YAEF,6BAA6B;YAC7B,MAAM,SAAS,GAAG;gBAChB,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ;gBAC3B,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,IAAI;aACd,CAAC;YAEF,kBAAkB;YAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAEhG,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;gBAC/B,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,EAAE,CAAC,iCAAiC;aAC3C,CAAC;SAEH;QAAC,OAAO,KAAU,EAAE;YACnB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,EAAE;gBACR,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC;SACH;IACH,CAAC;IAGD;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,MAAM,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,CAAC;IACrD,CAAC;CACF;AA5MD,4CA4MC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { App, JobDefinition, JobExecutionRequest, JobExecutionResponse } from '../types/app';
|
|
2
|
+
import { JobExecution } from '../local_engine/storage/LocalJobStore';
|
|
3
|
+
/**
|
|
4
|
+
* Executes jobs of an OCP app in isolated processes
|
|
5
|
+
*/
|
|
6
|
+
export declare class JobExecutor {
|
|
7
|
+
private appDir;
|
|
8
|
+
private app;
|
|
9
|
+
private jobStore;
|
|
10
|
+
private localEngineClient;
|
|
11
|
+
constructor(appDir: string, app: App);
|
|
12
|
+
/**
|
|
13
|
+
* Get job definitions from app manifest
|
|
14
|
+
*/
|
|
15
|
+
getJobs(): JobDefinition[];
|
|
16
|
+
/**
|
|
17
|
+
* Get job execution history
|
|
18
|
+
*/
|
|
19
|
+
getExecutions(jobId?: string): JobExecution[];
|
|
20
|
+
/**
|
|
21
|
+
* Get specific execution details
|
|
22
|
+
*/
|
|
23
|
+
getExecution(executionId: string): JobExecution | null;
|
|
24
|
+
/**
|
|
25
|
+
* Get execution state history
|
|
26
|
+
*/
|
|
27
|
+
getExecutionStates(executionId: string): import("../local_engine/storage/LocalJobStore").JobStateSnapshot[];
|
|
28
|
+
/**
|
|
29
|
+
* Start a job execution
|
|
30
|
+
*/
|
|
31
|
+
executeJob(request: JobExecutionRequest): Promise<JobExecutionResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Execute job asynchronously in the background
|
|
34
|
+
*/
|
|
35
|
+
private executeJobAsync;
|
|
36
|
+
/**
|
|
37
|
+
* Check if job file exists and is built
|
|
38
|
+
*/
|
|
39
|
+
validateJob(jobId: string): {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Get job statistics
|
|
45
|
+
*/
|
|
46
|
+
getStats(): {
|
|
47
|
+
totalExecutions: number;
|
|
48
|
+
runningExecutions: number;
|
|
49
|
+
completedExecutions: number;
|
|
50
|
+
failedExecutions: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Clean up old job executions
|
|
54
|
+
*/
|
|
55
|
+
cleanup(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Cleanup local engine connections when executor is destroyed
|
|
58
|
+
*/
|
|
59
|
+
dispose(): Promise<void>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.JobExecutor = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const app_1 = require("../types/app");
|
|
9
|
+
const LocalJobStore_1 = require("../local_engine/storage/LocalJobStore");
|
|
10
|
+
const local_engine_client_1 = require("../local_engine/local-engine-client");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
/**
|
|
13
|
+
* Executes jobs of an OCP app in isolated processes
|
|
14
|
+
*/
|
|
15
|
+
class JobExecutor {
|
|
16
|
+
constructor(appDir, app) {
|
|
17
|
+
this.appDir = appDir;
|
|
18
|
+
this.app = app;
|
|
19
|
+
this.jobStore = LocalJobStore_1.LocalJobStore.getInstance(appDir);
|
|
20
|
+
this.localEngineClient = new local_engine_client_1.LocalEngineClient();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get job definitions from app manifest
|
|
24
|
+
*/
|
|
25
|
+
getJobs() {
|
|
26
|
+
const jobs = [];
|
|
27
|
+
const manifest = this.app.manifest;
|
|
28
|
+
// Regular jobs
|
|
29
|
+
if (manifest.jobs) {
|
|
30
|
+
Object.entries(manifest.jobs).forEach(([id, job]) => {
|
|
31
|
+
jobs.push({
|
|
32
|
+
id,
|
|
33
|
+
entry_point: job.entry_point,
|
|
34
|
+
description: job.description,
|
|
35
|
+
cron: job.cron,
|
|
36
|
+
parameters: job.parameters,
|
|
37
|
+
isSourceJob: false
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Source jobs (nested under sources)
|
|
42
|
+
if (manifest.sources) {
|
|
43
|
+
Object.entries(manifest.sources).forEach(([sourceId, source]) => {
|
|
44
|
+
if (source.jobs) {
|
|
45
|
+
Object.entries(source.jobs).forEach(([jobId, job]) => {
|
|
46
|
+
jobs.push({
|
|
47
|
+
id: `${sourceId}_${jobId}`,
|
|
48
|
+
entry_point: job.entry_point,
|
|
49
|
+
description: job.description,
|
|
50
|
+
parameters: job.parameters,
|
|
51
|
+
isSourceJob: true
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return jobs;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get job execution history
|
|
61
|
+
*/
|
|
62
|
+
getExecutions(jobId) {
|
|
63
|
+
return this.jobStore.getExecutions(jobId);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get specific execution details
|
|
67
|
+
*/
|
|
68
|
+
getExecution(executionId) {
|
|
69
|
+
return this.jobStore.getExecution(executionId);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get execution state history
|
|
73
|
+
*/
|
|
74
|
+
getExecutionStates(executionId) {
|
|
75
|
+
return this.jobStore.getExecutionStates(executionId);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Start a job execution
|
|
79
|
+
*/
|
|
80
|
+
async executeJob(request) {
|
|
81
|
+
try {
|
|
82
|
+
// Validate job exists
|
|
83
|
+
const jobs = this.getJobs();
|
|
84
|
+
const jobDef = jobs.find(j => j.id === request.jobId);
|
|
85
|
+
if (!jobDef) {
|
|
86
|
+
throw new Error(`Job not found: ${request.jobId}`);
|
|
87
|
+
}
|
|
88
|
+
// Create execution record
|
|
89
|
+
const execution = this.jobStore.createExecution(request.jobId, request.parameters || {});
|
|
90
|
+
// Update status to running
|
|
91
|
+
this.jobStore.updateExecutionStatus(execution.id, LocalJobStore_1.JobExecutionStatus.RUNNING);
|
|
92
|
+
// Start job execution asynchronously (don't await)
|
|
93
|
+
this.executeJobAsync(request, execution.id).catch(error => {
|
|
94
|
+
console.error('Job execution failed:', error);
|
|
95
|
+
this.jobStore.updateExecutionStatus(execution.id, LocalJobStore_1.JobExecutionStatus.FAILED, {
|
|
96
|
+
message: error.message,
|
|
97
|
+
stack: error.stack
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
// Return immediately with running status
|
|
101
|
+
return {
|
|
102
|
+
success: true,
|
|
103
|
+
executionId: execution.id,
|
|
104
|
+
status: app_1.JobExecutionStatus.RUNNING,
|
|
105
|
+
startedAt: execution.startedAt,
|
|
106
|
+
logs: [],
|
|
107
|
+
executionTime: 0,
|
|
108
|
+
stateCount: 0
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return {
|
|
113
|
+
success: false,
|
|
114
|
+
executionId: (0, crypto_1.randomUUID)(),
|
|
115
|
+
status: app_1.JobExecutionStatus.FAILED,
|
|
116
|
+
startedAt: new Date(),
|
|
117
|
+
completedAt: new Date(),
|
|
118
|
+
logs: [],
|
|
119
|
+
error: {
|
|
120
|
+
message: error.message,
|
|
121
|
+
stack: error.stack
|
|
122
|
+
},
|
|
123
|
+
executionTime: 0,
|
|
124
|
+
stateCount: 0
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Execute job asynchronously in the background
|
|
130
|
+
*/
|
|
131
|
+
async executeJobAsync(request, executionId) {
|
|
132
|
+
const startTime = Date.now();
|
|
133
|
+
try {
|
|
134
|
+
// Prepare IPC request
|
|
135
|
+
const ipcRequest = {
|
|
136
|
+
jobId: request.jobId,
|
|
137
|
+
parameters: request.parameters || {},
|
|
138
|
+
dataSyncId: request.dataSyncId,
|
|
139
|
+
sourceKey: request.sourceKey,
|
|
140
|
+
executionId: executionId,
|
|
141
|
+
appDir: this.appDir
|
|
142
|
+
};
|
|
143
|
+
// Prepare app config for IPC
|
|
144
|
+
const appConfig = {
|
|
145
|
+
manifest: this.app.manifest,
|
|
146
|
+
path: this.appDir,
|
|
147
|
+
isBuilt: true,
|
|
148
|
+
isValid: true
|
|
149
|
+
};
|
|
150
|
+
// Execute via local engine
|
|
151
|
+
const result = await this.localEngineClient.executeJob(ipcRequest, appConfig, this.appDir);
|
|
152
|
+
// Update execution status
|
|
153
|
+
this.jobStore.updateExecutionStatus(executionId, LocalJobStore_1.JobExecutionStatus.COMPLETED);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error('Job execution failed:', error);
|
|
157
|
+
this.jobStore.updateExecutionStatus(executionId, LocalJobStore_1.JobExecutionStatus.FAILED, {
|
|
158
|
+
message: error.message,
|
|
159
|
+
stack: error.stack
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Check if job file exists and is built
|
|
165
|
+
*/
|
|
166
|
+
validateJob(jobId) {
|
|
167
|
+
const jobs = this.getJobs();
|
|
168
|
+
const jobDef = jobs.find(j => j.id === jobId);
|
|
169
|
+
if (!jobDef) {
|
|
170
|
+
return { valid: false, error: `Job not found: ${jobId}` };
|
|
171
|
+
}
|
|
172
|
+
// Check if built job file exists
|
|
173
|
+
const jobPath = path_1.default.join(this.appDir, 'dist', 'jobs', `${jobDef.entry_point}.js`);
|
|
174
|
+
const fs = require('fs');
|
|
175
|
+
if (!fs.existsSync(jobPath)) {
|
|
176
|
+
return {
|
|
177
|
+
valid: false,
|
|
178
|
+
error: `Job file not built or not found. Expected: dist/jobs/${jobDef.entry_point}.js`
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return { valid: true };
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get job statistics
|
|
185
|
+
*/
|
|
186
|
+
getStats() {
|
|
187
|
+
return this.jobStore.getStats();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Clean up old job executions
|
|
191
|
+
*/
|
|
192
|
+
cleanup() {
|
|
193
|
+
this.jobStore.cleanup();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Cleanup local engine connections when executor is destroyed
|
|
197
|
+
*/
|
|
198
|
+
async dispose() {
|
|
199
|
+
await this.localEngineClient.closeAllConnections();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.JobExecutor = JobExecutor;
|
|
203
|
+
//# sourceMappingURL=JobExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JobExecutor.js","sourceRoot":"","sources":["../../../src/executor/JobExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,sCAAiH;AACjH,yEAAmI;AACnI,6EAAwE;AAExE,mCAAoC;AAGpC;;GAEG;AACH,MAAa,WAAW;IAMtB,YAAY,MAAc,EAAE,GAAQ;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,6BAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,iBAAiB,GAAG,IAAI,uCAAiB,EAAE,CAAC;IACnD,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,MAAM,IAAI,GAAoB,EAAE,CAAC;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;QAEnC,eAAe;QACf,IAAI,QAAQ,CAAC,IAAI,EAAE;YACjB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAgB,EAAE,EAAE;gBACjE,IAAI,CAAC,IAAI,CAAC;oBACR,EAAE;oBACF,WAAW,EAAE,GAAG,CAAC,WAAW;oBAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;oBAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,UAAU,EAAE,GAAG,CAAC,UAAU;oBAC1B,WAAW,EAAE,KAAK;iBACnB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;QAED,qCAAqC;QACrC,IAAI,QAAQ,CAAC,OAAO,EAAE;YACpB,MAAM,CAAC,OAAO,CAAC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from '../local_engine/storage/LocalSettingsStore';
|
|
3
|
+
/**
|
|
4
|
+
* Executes lifecycle methods of an OCP app
|
|
5
|
+
*/
|
|
6
|
+
export declare class LifecycleExecutor {
|
|
7
|
+
private appDir;
|
|
8
|
+
private app;
|
|
9
|
+
private settingsStore;
|
|
10
|
+
private configStore;
|
|
11
|
+
private localEngineClient;
|
|
12
|
+
constructor(appDir: string, app: App, settingsStore: LocalSettingsStore, configStore: any);
|
|
13
|
+
/**
|
|
14
|
+
* Execute the onInstall lifecycle method
|
|
15
|
+
*/
|
|
16
|
+
executeInstall(): Promise<LifecycleHookExecutionResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Execute the onUninstall lifecycle method
|
|
19
|
+
*/
|
|
20
|
+
executeUninstall(): Promise<LifecycleHookExecutionResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Execute the canUninstall lifecycle method
|
|
23
|
+
*/
|
|
24
|
+
executeCanUninstall(): Promise<LifecycleHookExecutionResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute the onUpgrade lifecycle method
|
|
27
|
+
*/
|
|
28
|
+
executeUpgrade(fromVersion: string): Promise<LifecycleHookExecutionResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Execute the onSettingsForm lifecycle method
|
|
31
|
+
*/
|
|
32
|
+
executeSettingsForm(page: string, action: string, formData: any): Promise<LifecycleHookExecutionResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Execute a lifecycle method by running it in the app's built environment
|
|
35
|
+
*/
|
|
36
|
+
private executeLifecycleMethod;
|
|
37
|
+
/**
|
|
38
|
+
* Execute the lifecycle script using IPC
|
|
39
|
+
*/
|
|
40
|
+
private executeLifecycleScript;
|
|
41
|
+
/**
|
|
42
|
+
* Cleanup IPC connections when executor is destroyed
|
|
43
|
+
*/
|
|
44
|
+
cleanup(): Promise<void>;
|
|
45
|
+
}
|