@actiondock/core 2.0.12 → 2.2.1
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 +61 -30
- package/dist/app/app.d.ts +73 -0
- package/dist/app/app.js +700 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +2 -0
- package/dist/app/types.d.ts +283 -0
- package/dist/app/types.js +1 -0
- package/dist/catalog/action-index.d.ts +1 -1
- package/dist/catalog/action-index.js +93 -0
- package/dist/catalog/action-resolver.d.ts +2 -2
- package/dist/catalog/action-resolver.js +95 -0
- package/dist/catalog/index.d.ts +5 -5
- package/dist/catalog/index.js +5 -0
- package/dist/catalog/location-registry.d.ts +5 -5
- package/dist/catalog/location-registry.js +138 -0
- package/dist/catalog/package-catalog.d.ts +2 -2
- package/dist/catalog/package-catalog.js +76 -0
- package/dist/catalog/types.d.ts +2 -2
- package/dist/catalog/types.js +1 -0
- package/dist/doctor/doctor.d.ts +2 -1
- package/dist/doctor/doctor.js +613 -0
- package/dist/doctor/index.d.ts +2 -2
- package/dist/doctor/index.js +2 -0
- package/dist/doctor/types.js +1 -0
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +123 -0
- package/dist/execution/index.d.ts +2 -2
- package/dist/execution/index.js +2 -0
- package/dist/execution/service.d.ts +46 -41
- package/dist/execution/service.js +633 -0
- package/dist/execution/types.d.ts +59 -2
- package/dist/execution/types.js +1 -0
- package/dist/export/index.d.ts +1 -1
- package/dist/export/index.js +1 -0
- package/dist/export/templates.d.ts +45 -7
- package/dist/export/templates.js +631 -0
- package/dist/filter/index.d.ts +1 -1
- package/dist/filter/index.js +1 -0
- package/dist/filter/intent.js +123 -0
- package/dist/host/host.d.ts +55 -0
- package/dist/host/host.js +740 -0
- package/dist/host/index.d.ts +2 -0
- package/dist/host/index.js +2 -0
- package/dist/host/types.d.ts +81 -0
- package/dist/host/types.js +1 -0
- package/dist/index.d.ts +21 -16
- package/dist/index.js +20 -8458
- package/dist/ipc/diagnostic.d.ts +65 -0
- package/dist/ipc/diagnostic.js +129 -0
- package/dist/ipc/host.d.ts +7 -0
- package/dist/ipc/host.js +93 -0
- package/dist/ipc/index.d.ts +4 -0
- package/dist/ipc/index.js +4 -0
- package/dist/ipc/target.d.ts +56 -0
- package/dist/ipc/target.js +297 -0
- package/dist/ipc/types.d.ts +42 -0
- package/dist/ipc/types.js +1 -0
- package/dist/platform/default.d.ts +32 -0
- package/dist/platform/default.js +40 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.js +3 -0
- package/dist/platform/node-fs.d.ts +37 -0
- package/dist/platform/node-fs.js +81 -0
- package/dist/platform/types.d.ts +104 -0
- package/dist/platform/types.js +1 -0
- package/dist/profile/client.d.ts +58 -12
- package/dist/profile/client.js +467 -0
- package/dist/profile/index.d.ts +3 -3
- package/dist/profile/index.js +3 -0
- package/dist/profile/manager.d.ts +2 -2
- package/dist/profile/manager.js +294 -0
- package/dist/profile/types.d.ts +1 -1
- package/dist/profile/types.js +1 -0
- package/dist/project/closure.js +68 -0
- package/dist/project/digest.d.ts +29 -0
- package/dist/project/digest.js +324 -0
- package/dist/project/index.d.ts +10 -5
- package/dist/project/index.js +10 -0
- package/dist/project/init.d.ts +3 -4
- package/dist/project/init.js +175 -0
- package/dist/project/loader.d.ts +21 -27
- package/dist/project/loader.js +484 -0
- package/dist/project/lockfile.d.ts +55 -0
- package/dist/project/lockfile.js +175 -0
- package/dist/project/manifest.d.ts +6 -28
- package/dist/project/manifest.js +220 -0
- package/dist/project/resolver.d.ts +116 -0
- package/dist/project/resolver.js +376 -0
- package/dist/project/transactions.d.ts +103 -0
- package/dist/project/transactions.js +1203 -0
- package/dist/project/types-generator.d.ts +33 -0
- package/dist/project/types-generator.js +168 -0
- package/dist/project/types.d.ts +58 -82
- package/dist/project/types.js +1 -0
- package/dist/registry/index.d.ts +5 -2
- package/dist/registry/index.js +5 -0
- package/dist/registry/lock.d.ts +27 -0
- package/dist/registry/lock.js +93 -0
- package/dist/registry/registry.d.ts +32 -11
- package/dist/registry/registry.js +611 -0
- package/dist/registry/resolve.d.ts +62 -0
- package/dist/registry/resolve.js +195 -0
- package/dist/registry/scan.d.ts +38 -0
- package/dist/registry/scan.js +135 -0
- package/dist/registry/types.d.ts +1 -1
- package/dist/registry/types.js +1 -0
- package/dist/runtime/action-collection.d.ts +27 -0
- package/dist/runtime/action-collection.js +57 -0
- package/dist/runtime/clock.d.ts +0 -2
- package/dist/runtime/clock.js +17 -0
- package/dist/runtime/context.d.ts +16 -5
- package/dist/runtime/context.js +242 -0
- package/dist/runtime/env.d.ts +3 -1
- package/dist/runtime/env.js +159 -0
- package/dist/runtime/events.d.ts +46 -14
- package/dist/runtime/events.js +604 -0
- package/dist/runtime/execution-manager.d.ts +1 -1
- package/dist/runtime/execution-manager.js +66 -0
- package/dist/runtime/index.d.ts +10 -9
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/module-loader.d.ts +0 -8
- package/dist/runtime/module-loader.js +16 -0
- package/dist/runtime/process.d.ts +2 -4
- package/dist/runtime/process.js +146 -0
- package/dist/runtime/runner.d.ts +117 -10
- package/dist/runtime/runner.js +984 -0
- package/dist/runtime/standalone.d.ts +68 -19
- package/dist/runtime/standalone.js +536 -0
- package/dist/schema/validator.js +122 -0
- package/dist/server/body.js +93 -0
- package/dist/server/index.d.ts +5 -6
- package/dist/server/index.js +5 -0
- package/dist/server/routes/actions.d.ts +2 -2
- package/dist/server/routes/actions.js +298 -0
- package/dist/server/routes/common.d.ts +28 -17
- package/dist/server/routes/common.js +104 -0
- package/dist/server/routes/config.d.ts +2 -1
- package/dist/server/routes/config.js +173 -0
- package/dist/server/routes/doctor.d.ts +2 -2
- package/dist/server/routes/doctor.js +63 -0
- package/dist/server/routes/health.d.ts +2 -2
- package/dist/server/routes/health.js +35 -0
- package/dist/server/routes/index.d.ts +9 -9
- package/dist/server/routes/index.js +9 -0
- package/dist/server/routes/info.d.ts +4 -2
- package/dist/server/routes/info.js +158 -0
- package/dist/server/routes/playbooks.d.ts +2 -2
- package/dist/server/routes/playbooks.js +134 -0
- package/dist/server/routes/runs.d.ts +2 -2
- package/dist/server/routes/runs.js +343 -0
- package/dist/server/routes/state.d.ts +2 -1
- package/dist/server/routes/state.js +169 -0
- package/dist/server/security.d.ts +11 -4
- package/dist/server/security.js +101 -0
- package/dist/server/server.d.ts +6 -6
- package/dist/server/server.js +355 -0
- package/dist/server/types.d.ts +27 -8
- package/dist/server/types.js +1 -0
- package/dist/storage/data-dir-lock.d.ts +119 -0
- package/dist/storage/data-dir-lock.js +1016 -0
- package/dist/storage/driver.d.ts +4 -10
- package/dist/storage/driver.js +59 -0
- package/dist/storage/index.d.ts +30 -10
- package/dist/storage/index.js +98 -0
- package/dist/storage/lazy.d.ts +8 -0
- package/dist/storage/lazy.js +44 -0
- package/dist/storage/mask.d.ts +12 -5
- package/dist/storage/mask.js +48 -0
- package/dist/storage/params.d.ts +13 -0
- package/dist/storage/params.js +32 -0
- package/dist/storage/sqlite.d.ts +19 -6
- package/dist/storage/sqlite.js +689 -0
- package/dist/storage/types.d.ts +57 -6
- package/dist/storage/types.js +14 -0
- package/dist/target/index.d.ts +4 -0
- package/dist/target/index.js +4 -0
- package/dist/target/local.d.ts +52 -0
- package/dist/target/local.js +343 -0
- package/dist/target/remote.d.ts +76 -0
- package/dist/target/remote.js +839 -0
- package/dist/target/target.d.ts +6 -0
- package/dist/target/target.js +35 -0
- package/dist/target/types.d.ts +246 -0
- package/dist/target/types.js +34 -0
- package/dist/utils/index.d.ts +22 -2
- package/dist/utils/index.js +180 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +4 -0
- package/package.json +6 -7
- package/dist/build/index.d.ts +0 -1
- package/dist/build/templates.d.ts +0 -19
- package/dist/server/runtime-registry.d.ts +0 -78
package/dist/storage/driver.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { normalizeSqliteParams } from "./params.js";
|
|
2
|
+
import type { SqliteDriver } from "./types.js";
|
|
2
3
|
export type SqliteDriverFactory = (dbPath: string) => SqliteDriver;
|
|
3
|
-
|
|
4
|
-
* 获取当前注册的全局默认 SQLite 驱动工厂。
|
|
5
|
-
*/
|
|
6
|
-
export declare function getSqliteDriverFactory(): SqliteDriverFactory | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* 注册全局默认 SQLite 驱动工厂。
|
|
9
|
-
*/
|
|
10
|
-
export declare function setSqliteDriverFactory(factory: SqliteDriverFactory): void;
|
|
4
|
+
export { normalizeSqliteParams };
|
|
11
5
|
/**
|
|
12
6
|
* 创建默认 SQLite 驱动实例。
|
|
13
|
-
*
|
|
7
|
+
* 基于 Node.js 原生 node:sqlite (DatabaseSync) 驱动实现,严格同步契约。
|
|
14
8
|
*/
|
|
15
9
|
export declare function createDefaultSqliteDriver(dbPath: string): SqliteDriver;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { normalizeSqliteParams } from "./params.js";
|
|
3
|
+
export { normalizeSqliteParams };
|
|
4
|
+
/** ESM 环境下可用的 CommonJS require,用于动态加载 node:sqlite */
|
|
5
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
6
|
+
/**
|
|
7
|
+
* 创建默认 SQLite 驱动实例。
|
|
8
|
+
* 基于 Node.js 原生 node:sqlite (DatabaseSync) 驱动实现,严格同步契约。
|
|
9
|
+
*/
|
|
10
|
+
export function createDefaultSqliteDriver(dbPath) {
|
|
11
|
+
try {
|
|
12
|
+
const { DatabaseSync } = cjsRequire("node:sqlite");
|
|
13
|
+
const db = new DatabaseSync(dbPath);
|
|
14
|
+
return {
|
|
15
|
+
exec(sql) {
|
|
16
|
+
db.exec(sql);
|
|
17
|
+
},
|
|
18
|
+
prepare(sql) {
|
|
19
|
+
const stmt = db.prepare(sql);
|
|
20
|
+
return {
|
|
21
|
+
run(...args) {
|
|
22
|
+
const params = normalizeSqliteParams(args);
|
|
23
|
+
const res = stmt.run(...params);
|
|
24
|
+
return { changes: res.changes, lastInsertRowid: res.lastInsertRowid };
|
|
25
|
+
},
|
|
26
|
+
get(...args) {
|
|
27
|
+
const params = normalizeSqliteParams(args);
|
|
28
|
+
return stmt.get(...params);
|
|
29
|
+
},
|
|
30
|
+
all(...args) {
|
|
31
|
+
const params = normalizeSqliteParams(args);
|
|
32
|
+
return stmt.all(...params);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
transaction(fn) {
|
|
37
|
+
db.exec("BEGIN");
|
|
38
|
+
try {
|
|
39
|
+
const res = fn();
|
|
40
|
+
if (res !== null && (typeof res === "object" || typeof res === "function") && typeof res.then === "function") {
|
|
41
|
+
throw new Error("Async transactions are not allowed in SQLite");
|
|
42
|
+
}
|
|
43
|
+
db.exec("COMMIT");
|
|
44
|
+
return res;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
db.exec("ROLLBACK");
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
close() {
|
|
52
|
+
db.close();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
throw new Error(`Failed to initialize SQLite driver: ${err?.message || String(err)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import type { RuntimeStorage } from "./types";
|
|
2
|
-
export
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
1
|
+
import type { RuntimeStorage } from "./types.js";
|
|
2
|
+
export { DataDirLock, type DataDirLockInfo, isProcessAlive, } from "./data-dir-lock.js";
|
|
3
|
+
export * from "./driver.js";
|
|
4
|
+
export * from "./lazy.js";
|
|
5
|
+
export * from "./mask.js";
|
|
6
|
+
export * from "./params.js";
|
|
7
|
+
export * from "./sqlite.js";
|
|
8
|
+
export * from "./types.js";
|
|
6
9
|
/**
|
|
7
10
|
* 解析并计算目标 SQLite 数据库文件的绝对路径。
|
|
8
11
|
*
|
|
9
12
|
* 优先级规则:
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* 4. 默认独立二进制存储路径 -> 返回 `~/.actiondock/data/<packageId>/runtime.db`
|
|
13
|
+
* - inMemory: true -> 返回 ":memory:"
|
|
14
|
+
* - 显式指定 dataDir -> 返回 `<dataDir>/<packageId>/runtime.db`
|
|
15
|
+
* - 默认统一数据存储路径 -> 返回 `~/.actiondock/data/<packageId>/runtime.db`
|
|
14
16
|
*
|
|
15
17
|
* @param packageId 所属 Package ID
|
|
16
18
|
* @param options 路径解析选项
|
|
@@ -19,18 +21,35 @@ export declare function resolveDatabasePath(packageId: string, options?: {
|
|
|
19
21
|
projectRoot?: string;
|
|
20
22
|
dataDir?: string;
|
|
21
23
|
inMemory?: boolean;
|
|
24
|
+
customHome?: string;
|
|
22
25
|
}): string;
|
|
23
26
|
/**
|
|
24
27
|
* 工厂函数:为指定 Package 创建或连接 RuntimeStorage 实例。
|
|
25
28
|
*
|
|
26
29
|
* @param packageId 目标 Package ID
|
|
27
|
-
* @param options 存储配置参数(支持
|
|
30
|
+
* @param options 存储配置参数(支持 dataDir, inMemory, customHome)
|
|
28
31
|
*/
|
|
29
32
|
export declare function createStorage(packageId: string, options?: {
|
|
30
33
|
projectRoot?: string;
|
|
31
34
|
dataDir?: string;
|
|
32
35
|
inMemory?: boolean;
|
|
36
|
+
customHome?: string;
|
|
33
37
|
}): RuntimeStorage;
|
|
38
|
+
/**
|
|
39
|
+
* 解析全局共享数据库(global.db)文件的绝对路径。
|
|
40
|
+
*
|
|
41
|
+
* 单一事实源:core 与各运行时平台适配层(如 runtime-node)
|
|
42
|
+
* 统一调用本函数计算 global.db 路径,禁止在适配层内重复拼接过
|
|
43
|
+
* 路径规则,避免双实现漂移。
|
|
44
|
+
*
|
|
45
|
+
* 优先级规则:
|
|
46
|
+
* - 显式指定 dataDir -> 返回 `<dataDir>/global.db`
|
|
47
|
+
* - 默认路径 -> 返回 `~/.actiondock/global.db`
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveGlobalDatabasePath(options?: {
|
|
50
|
+
dataDir?: string;
|
|
51
|
+
customHome?: string;
|
|
52
|
+
}): string;
|
|
34
53
|
/**
|
|
35
54
|
* 工厂函数:创建或连接 ActionDock 全局共享数据库(~/.actiondock/global.db)。
|
|
36
55
|
* 用于跨 Package 共享的全局配置项存储。
|
|
@@ -41,4 +60,5 @@ export declare function createStorage(packageId: string, options?: {
|
|
|
41
60
|
export declare function createGlobalStorage(customHomeOrOptions?: string | {
|
|
42
61
|
customHome?: string;
|
|
43
62
|
dataDir?: string;
|
|
63
|
+
inMemory?: boolean;
|
|
44
64
|
}, dataDirArg?: string): RuntimeStorage;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { join, relative, resolve } from "node:path";
|
|
2
|
+
import { assertValidPackageId, getActionDockHome, isPathOutsideBoundary } from "../utils/index.js";
|
|
3
|
+
import { SqliteRuntimeStorage } from "./sqlite.js";
|
|
4
|
+
export { DataDirLock, isProcessAlive, } from "./data-dir-lock.js";
|
|
5
|
+
export * from "./driver.js";
|
|
6
|
+
export * from "./lazy.js";
|
|
7
|
+
export * from "./mask.js";
|
|
8
|
+
export * from "./params.js";
|
|
9
|
+
export * from "./sqlite.js";
|
|
10
|
+
export * from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* 解析并计算目标 SQLite 数据库文件的绝对路径。
|
|
13
|
+
*
|
|
14
|
+
* 优先级规则:
|
|
15
|
+
* - inMemory: true -> 返回 ":memory:"
|
|
16
|
+
* - 显式指定 dataDir -> 返回 `<dataDir>/<packageId>/runtime.db`
|
|
17
|
+
* - 默认统一数据存储路径 -> 返回 `~/.actiondock/data/<packageId>/runtime.db`
|
|
18
|
+
*
|
|
19
|
+
* @param packageId 所属 Package ID
|
|
20
|
+
* @param options 路径解析选项
|
|
21
|
+
*/
|
|
22
|
+
export function resolveDatabasePath(packageId, options = {}) {
|
|
23
|
+
if (options.inMemory) {
|
|
24
|
+
return ":memory:";
|
|
25
|
+
}
|
|
26
|
+
assertValidPackageId(packageId);
|
|
27
|
+
// 安全子路径(支持 @scope/pkg 规范,拒绝非法字符与相对回退)
|
|
28
|
+
const safePkgPath = packageId.startsWith("@") ? packageId.slice(1) : packageId;
|
|
29
|
+
if (options.dataDir) {
|
|
30
|
+
const rootDir = resolve(options.dataDir);
|
|
31
|
+
const dbPath = resolve(rootDir, safePkgPath, "runtime.db");
|
|
32
|
+
const rel = relative(rootDir, dbPath);
|
|
33
|
+
if (isPathOutsideBoundary(rel)) {
|
|
34
|
+
throw new Error(`'database dataDir path' escapes boundary '${rootDir}': ${dbPath}`);
|
|
35
|
+
}
|
|
36
|
+
return dbPath;
|
|
37
|
+
}
|
|
38
|
+
// 统一数据存储路径: ~/.actiondock/data/<package-id>/runtime.db
|
|
39
|
+
const rootDir = resolve(join(getActionDockHome(options.customHome), ".actiondock", "data"));
|
|
40
|
+
const dbPath = resolve(rootDir, safePkgPath, "runtime.db");
|
|
41
|
+
const rel = relative(rootDir, dbPath);
|
|
42
|
+
if (isPathOutsideBoundary(rel)) {
|
|
43
|
+
throw new Error(`'database storage path' escapes boundary '${rootDir}': ${dbPath}`);
|
|
44
|
+
}
|
|
45
|
+
return dbPath;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 工厂函数:为指定 Package 创建或连接 RuntimeStorage 实例。
|
|
49
|
+
*
|
|
50
|
+
* @param packageId 目标 Package ID
|
|
51
|
+
* @param options 存储配置参数(支持 dataDir, inMemory, customHome)
|
|
52
|
+
*/
|
|
53
|
+
export function createStorage(packageId, options = {}) {
|
|
54
|
+
const dbPath = resolveDatabasePath(packageId, options);
|
|
55
|
+
return new SqliteRuntimeStorage({ dbPath, packageId });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 解析全局共享数据库(global.db)文件的绝对路径。
|
|
59
|
+
*
|
|
60
|
+
* 单一事实源:core 与各运行时平台适配层(如 runtime-node)
|
|
61
|
+
* 统一调用本函数计算 global.db 路径,禁止在适配层内重复拼接过
|
|
62
|
+
* 路径规则,避免双实现漂移。
|
|
63
|
+
*
|
|
64
|
+
* 优先级规则:
|
|
65
|
+
* - 显式指定 dataDir -> 返回 `<dataDir>/global.db`
|
|
66
|
+
* - 默认路径 -> 返回 `~/.actiondock/global.db`
|
|
67
|
+
*/
|
|
68
|
+
export function resolveGlobalDatabasePath(options = {}) {
|
|
69
|
+
return options.dataDir
|
|
70
|
+
? join(options.dataDir, "global.db")
|
|
71
|
+
: join(getActionDockHome(options.customHome), ".actiondock", "global.db");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 工厂函数:创建或连接 ActionDock 全局共享数据库(~/.actiondock/global.db)。
|
|
75
|
+
* 用于跨 Package 共享的全局配置项存储。
|
|
76
|
+
*
|
|
77
|
+
* @param customHomeOrOptions 自定义家目录路径或配置对象(可选)
|
|
78
|
+
* @param dataDirArg 自定义数据存储目录(可选)
|
|
79
|
+
*/
|
|
80
|
+
export function createGlobalStorage(customHomeOrOptions, dataDirArg) {
|
|
81
|
+
let customHome;
|
|
82
|
+
let dataDir;
|
|
83
|
+
let inMemory = false;
|
|
84
|
+
if (typeof customHomeOrOptions === "object" && customHomeOrOptions !== null) {
|
|
85
|
+
customHome = customHomeOrOptions.customHome;
|
|
86
|
+
dataDir = customHomeOrOptions.dataDir;
|
|
87
|
+
inMemory = Boolean(customHomeOrOptions.inMemory);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
customHome = customHomeOrOptions;
|
|
91
|
+
dataDir = dataDirArg;
|
|
92
|
+
}
|
|
93
|
+
if (inMemory) {
|
|
94
|
+
return new SqliteRuntimeStorage({ dbPath: ":memory:", packageId: "__global__" });
|
|
95
|
+
}
|
|
96
|
+
const dbPath = resolveGlobalDatabasePath({ dataDir, customHome });
|
|
97
|
+
return new SqliteRuntimeStorage({ dbPath, packageId: "__global__" });
|
|
98
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建延迟初始化的运行时存储代理对象。
|
|
3
|
+
* 只有在首次调用存储的方法或属性时,才会调用底层工厂函数建立真实连接。
|
|
4
|
+
*
|
|
5
|
+
* @param factory 底层存储实例工厂函数
|
|
6
|
+
*/
|
|
7
|
+
export function createLazyStorage(factory) {
|
|
8
|
+
let instance;
|
|
9
|
+
function getInstance() {
|
|
10
|
+
if (!instance) {
|
|
11
|
+
instance = factory();
|
|
12
|
+
}
|
|
13
|
+
return instance;
|
|
14
|
+
}
|
|
15
|
+
return new Proxy({}, {
|
|
16
|
+
get(_target, prop, receiver) {
|
|
17
|
+
if (prop === "closed") {
|
|
18
|
+
return instance ? instance.closed : false;
|
|
19
|
+
}
|
|
20
|
+
if (prop === "isOpen") {
|
|
21
|
+
return instance ? instance.isOpen : false;
|
|
22
|
+
}
|
|
23
|
+
if (prop === "close") {
|
|
24
|
+
return () => {
|
|
25
|
+
if (instance) {
|
|
26
|
+
instance.close();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (prop === "__isLazyProxy") {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (prop === "__getUnderlyingInstance") {
|
|
34
|
+
return getInstance;
|
|
35
|
+
}
|
|
36
|
+
const target = getInstance();
|
|
37
|
+
const value = Reflect.get(target, prop, receiver);
|
|
38
|
+
if (typeof value === "function") {
|
|
39
|
+
return value.bind(target);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
package/dist/storage/mask.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { ConfigItemDefinition } from "../project/types";
|
|
1
|
+
import type { ConfigItemDefinition } from "../project/types.js";
|
|
2
2
|
/**
|
|
3
3
|
* 检查指定配置项是否为敏感数据(密码、私钥、Token、密钥等)。
|
|
4
4
|
*
|
|
5
5
|
* 判定逻辑:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* 严格依据配置项元数据属性判定:若声明了 `secret: true`,直接判定为敏感数据;否则不视为敏感数据。
|
|
7
|
+
* 不进行基于正则或键名的自动探测,由开发者显式配置驱动。
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param _key 配置键名(保留入参以兼容契约)
|
|
10
10
|
* @param declaredItem 项目中声明的配置元数据(可选)
|
|
11
11
|
*/
|
|
12
|
-
export declare function isSecretConfigKey(
|
|
12
|
+
export declare function isSecretConfigKey(_key?: string, declaredItem?: ConfigItemDefinition): boolean;
|
|
13
13
|
/**
|
|
14
14
|
* 对敏感数据的值进行掩码脱敏处理(返回 "********")。
|
|
15
15
|
*
|
|
@@ -17,3 +17,10 @@ export declare function isSecretConfigKey(key: string, declaredItem?: ConfigItem
|
|
|
17
17
|
* @returns 掩码脱敏后的安全展示字符串
|
|
18
18
|
*/
|
|
19
19
|
export declare function maskSecretValue(value: unknown): string;
|
|
20
|
+
/**
|
|
21
|
+
* 对配置定义字典进行脱敏处理:
|
|
22
|
+
* 针对声明为 secret: true 的项,剥离其 default 默认值,不返回敏感默认值。
|
|
23
|
+
*
|
|
24
|
+
* @param config 声明的配置定义字典
|
|
25
|
+
*/
|
|
26
|
+
export declare function sanitizeConfigDefinitions(config?: Record<string, ConfigItemDefinition>): Record<string, ConfigItemDefinition> | undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查指定配置项是否为敏感数据(密码、私钥、Token、密钥等)。
|
|
3
|
+
*
|
|
4
|
+
* 判定逻辑:
|
|
5
|
+
* 严格依据配置项元数据属性判定:若声明了 `secret: true`,直接判定为敏感数据;否则不视为敏感数据。
|
|
6
|
+
* 不进行基于正则或键名的自动探测,由开发者显式配置驱动。
|
|
7
|
+
*
|
|
8
|
+
* @param _key 配置键名(保留入参以兼容契约)
|
|
9
|
+
* @param declaredItem 项目中声明的配置元数据(可选)
|
|
10
|
+
*/
|
|
11
|
+
export function isSecretConfigKey(_key, declaredItem) {
|
|
12
|
+
return declaredItem?.secret === true;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 对敏感数据的值进行掩码脱敏处理(返回 "********")。
|
|
16
|
+
*
|
|
17
|
+
* @param value 原始数据值
|
|
18
|
+
* @returns 掩码脱敏后的安全展示字符串
|
|
19
|
+
*/
|
|
20
|
+
export function maskSecretValue(value) {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return "undefined";
|
|
23
|
+
if (value === null)
|
|
24
|
+
return "null";
|
|
25
|
+
return "********";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 对配置定义字典进行脱敏处理:
|
|
29
|
+
* 针对声明为 secret: true 的项,剥离其 default 默认值,不返回敏感默认值。
|
|
30
|
+
*
|
|
31
|
+
* @param config 声明的配置定义字典
|
|
32
|
+
*/
|
|
33
|
+
export function sanitizeConfigDefinitions(config) {
|
|
34
|
+
if (!config)
|
|
35
|
+
return config;
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, item] of Object.entries(config)) {
|
|
38
|
+
if (item?.secret === true) {
|
|
39
|
+
const copy = { ...item };
|
|
40
|
+
delete copy.default;
|
|
41
|
+
result[key] = copy;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result[key] = item;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite 绑定参数规范化共享纯函数。
|
|
3
|
+
*
|
|
4
|
+
* 单一事实源:主线程驱动(core 默认驱动与 runtime-node 的 NodeSqliteDriver)
|
|
5
|
+
* 与 WorkerSqliteDriver 的 worker 内联脚本均使用本模块生成的同一份实现。
|
|
6
|
+
*
|
|
7
|
+
* 工程说明:worker 内联脚本以字符串形式 eval 执行、无法直接 import 模块,
|
|
8
|
+
* 因此 worker 侧通过 Function.prototype.toString 将本函数源码序列化注入脚本。
|
|
9
|
+
* 该函数必须保持完全自包含:仅依赖运行时全局 Buffer 与 Uint8Array,
|
|
10
|
+
* 不得引用任何模块作用域内的其他标识符,也不得引入会被打包器改写的外部闭包,
|
|
11
|
+
* 否则序列化注入后将在 worker 作用域内产生未定义引用。
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeSqliteParams(args: any[]): any[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite 绑定参数规范化共享纯函数。
|
|
3
|
+
*
|
|
4
|
+
* 单一事实源:主线程驱动(core 默认驱动与 runtime-node 的 NodeSqliteDriver)
|
|
5
|
+
* 与 WorkerSqliteDriver 的 worker 内联脚本均使用本模块生成的同一份实现。
|
|
6
|
+
*
|
|
7
|
+
* 工程说明:worker 内联脚本以字符串形式 eval 执行、无法直接 import 模块,
|
|
8
|
+
* 因此 worker 侧通过 Function.prototype.toString 将本函数源码序列化注入脚本。
|
|
9
|
+
* 该函数必须保持完全自包含:仅依赖运行时全局 Buffer 与 Uint8Array,
|
|
10
|
+
* 不得引用任何模块作用域内的其他标识符,也不得引入会被打包器改写的外部闭包,
|
|
11
|
+
* 否则序列化注入后将在 worker 作用域内产生未定义引用。
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeSqliteParams(args) {
|
|
14
|
+
if (!args || args.length === 0) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
if (args.length === 1 && Array.isArray(args[0])) {
|
|
18
|
+
return args[0].map((v) => (v === undefined ? null : v));
|
|
19
|
+
}
|
|
20
|
+
if (args.length === 1 &&
|
|
21
|
+
typeof args[0] === "object" &&
|
|
22
|
+
args[0] !== null &&
|
|
23
|
+
!Buffer.isBuffer(args[0]) &&
|
|
24
|
+
!(args[0] instanceof Uint8Array)) {
|
|
25
|
+
const cleaned = {};
|
|
26
|
+
for (const entry of Object.entries(args[0])) {
|
|
27
|
+
cleaned[entry[0]] = entry[1] === undefined ? null : entry[1];
|
|
28
|
+
}
|
|
29
|
+
return [cleaned];
|
|
30
|
+
}
|
|
31
|
+
return args.map((v) => (v === undefined ? null : v));
|
|
32
|
+
}
|
package/dist/storage/sqlite.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { decodeStateKey, encodeStateKey, escapeStateSegment, unescapeStateSegment, type RuntimeError, type RunRecord } from "@actiondock/sdk";
|
|
2
|
-
import type
|
|
2
|
+
import { type IdempotencyCheckResult, type IdempotencyRecord, type RuntimeStorage, type StateEntry, type StorageOptions, type TerminalRunStatus } from "./types.js";
|
|
3
3
|
export { decodeStateKey, encodeStateKey, escapeStateSegment, unescapeStateSegment, };
|
|
4
4
|
/**
|
|
5
5
|
* 统一 SQLite 运行时存储实现。
|
|
6
|
-
* 通过 SqliteDriver
|
|
6
|
+
* 通过 SqliteDriver 抽象驱动,解耦底层具体运行时引擎。
|
|
7
7
|
*/
|
|
8
8
|
export declare class SqliteRuntimeStorage implements RuntimeStorage {
|
|
9
9
|
private driver;
|
|
@@ -11,17 +11,28 @@ export declare class SqliteRuntimeStorage implements RuntimeStorage {
|
|
|
11
11
|
private clock;
|
|
12
12
|
private isClosed;
|
|
13
13
|
private statementCache;
|
|
14
|
+
private dbPath;
|
|
14
15
|
get isOpen(): boolean;
|
|
15
16
|
get closed(): boolean;
|
|
16
17
|
constructor(options: StorageOptions);
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* 初始化数据库结构并执行严格版本校验。
|
|
20
|
+
*
|
|
21
|
+
* 规则:
|
|
22
|
+
* - 空数据目录首次初始化在单个事务中完成完整 Schema 构建。
|
|
23
|
+
* - 若创建事务失败则拒绝启动且不留下残缺表。
|
|
24
|
+
* - 打开旧版本或不兼容版本的数据库时,在写事务前直接抛出 UNSUPPORTED_STORAGE_SCHEMA 异常并拒绝启动。
|
|
19
25
|
*/
|
|
20
26
|
private init;
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
28
|
+
* 重启恢复:将未正常结算的非终态(running/pending)记录自动收敛为 interrupted。
|
|
29
|
+
* 若指定了当前新 Host 会话标识,将收敛不属于该会话(包括旧会话或空会话)的死亡任务。
|
|
23
30
|
*/
|
|
24
|
-
recoverRunningRuns(): number;
|
|
31
|
+
recoverRunningRuns(currentHostSessionId?: string): number;
|
|
32
|
+
/**
|
|
33
|
+
* 收敛死亡会话遗留的非终态运行任务。
|
|
34
|
+
*/
|
|
35
|
+
recoverDeadSessionRuns(currentHostSessionId?: string): number;
|
|
25
36
|
/**
|
|
26
37
|
* 获取或复用预编译 SQL 语句缓存。
|
|
27
38
|
*/
|
|
@@ -61,6 +72,8 @@ export declare class SqliteRuntimeStorage implements RuntimeStorage {
|
|
|
61
72
|
actionId?: string;
|
|
62
73
|
status?: string;
|
|
63
74
|
}): number;
|
|
75
|
+
checkAndRecordIdempotency(record: IdempotencyRecord): IdempotencyCheckResult;
|
|
76
|
+
getIdempotencyRecord(ownerId: string, actionRef: string, requestId: string): IdempotencyRecord | undefined;
|
|
64
77
|
private mapRunRecord;
|
|
65
|
-
close(): void
|
|
78
|
+
close(): Promise<void>;
|
|
66
79
|
}
|