@feng0531/dsh-execution-bus 0.12.1 → 1.0.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/README.md +47 -264
- package/cordis.patch.yml +1 -1
- package/dist/error-codes.d.ts +14 -0
- package/dist/error-codes.js +15 -0
- package/dist/mode.d.ts +2 -2
- package/dist/mode.js +7 -7
- package/dist/plugin.d.ts +2 -6
- package/dist/plugin.js +28 -232
- package/dist/preset.d.ts +1 -1
- package/dist/preset.js +4 -6
- package/dist/product.d.ts +91 -195
- package/dist/product.js +66 -146
- package/dist/runtime/executor.d.ts +18 -0
- package/dist/runtime/executor.js +239 -0
- package/dist/runtime/plan.d.ts +30 -0
- package/dist/runtime/plan.js +185 -0
- package/dist/runtime/service.d.ts +66 -0
- package/dist/runtime/service.js +185 -0
- package/dist/runtime/store.d.ts +45 -0
- package/dist/runtime/store.js +102 -0
- package/docs/DECLARATIVE-RUNTIME.md +44 -0
- package/docs/FLOW-TEST.md +7 -54
- package/docs/INTEGRATION.md +3 -1
- package/docs/PRODUCT.md +15 -42
- package/docs/RETROSPECTIVE.md +51 -0
- package/docs/host-compatibility.md +11 -74
- package/docs/protocol.md +27 -135
- package/docs/releases/1.0.0.md +33 -0
- package/docs/validation.md +23 -62
- package/package.json +4 -6
- package/dist/bus.d.ts +0 -153
- package/dist/bus.js +0 -833
- package/dist/diagnostics.d.ts +0 -41
- package/dist/diagnostics.js +0 -32
- package/dist/execution.d.ts +0 -70
- package/dist/execution.js +0 -193
- package/dist/handlers.d.ts +0 -27
- package/dist/handlers.js +0 -194
- package/dist/json.d.ts +0 -4
- package/dist/json.js +0 -46
- package/dist/limits.d.ts +0 -20
- package/dist/limits.js +0 -23
- package/dist/protocol.d.ts +0 -62
- package/dist/protocol.js +0 -54
package/dist/protocol.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export type State = "queued" | "running" | "succeeded" | "failed" | "cancelled" | "unknown";
|
|
2
|
-
export type Owner = {
|
|
3
|
-
sessionId: string;
|
|
4
|
-
callId: string;
|
|
5
|
-
};
|
|
6
|
-
export type Message = {
|
|
7
|
-
protocolVersion: 1;
|
|
8
|
-
messageId: string;
|
|
9
|
-
requestId: string;
|
|
10
|
-
type: "request" | "status" | "result" | "cancel";
|
|
11
|
-
payload: Record<string, unknown>;
|
|
12
|
-
};
|
|
13
|
-
export type Event = {
|
|
14
|
-
protocolVersion: 1;
|
|
15
|
-
messageId: string;
|
|
16
|
-
requestId: string;
|
|
17
|
-
correlationId: string;
|
|
18
|
-
sequence: number;
|
|
19
|
-
type: string;
|
|
20
|
-
payload: Record<string, unknown>;
|
|
21
|
-
};
|
|
22
|
-
export type Capability = (input: Record<string, unknown>, signal: AbortSignal) => Promise<unknown>;
|
|
23
|
-
export interface Handler {
|
|
24
|
-
/** 是否可安全复用终态结果。省略默认 true(可复用,向后兼容);
|
|
25
|
-
* 显式 false = 有副作用,终态结果复用将被拒绝(运行中等待仍放行)。 */
|
|
26
|
-
readonly idempotent?: boolean;
|
|
27
|
-
/** 调度队列类别;默认按 "default"。不同类别之间按类别优先级 + 等待老化排序,
|
|
28
|
-
* 避免长任务类独占出队顺序。 */
|
|
29
|
-
readonly queue?: string;
|
|
30
|
-
/** 同一 Handler 同时在跑的上限;省略表示只受全局并发限制(舱壁)。 */
|
|
31
|
-
readonly maxConcurrency?: number;
|
|
32
|
-
/** 可选资源键(如文件路径):同键请求在总线内互斥,避免并发写同一资源。
|
|
33
|
-
* 由 Handler 在执行前从输入推导;返回空数组表示不占用资源。 */
|
|
34
|
-
resources?(input: Record<string, unknown>): readonly string[];
|
|
35
|
-
/** 唯一任务策略:"payload" 表示幂等只读 Handler 可按 handler+input 指纹复用
|
|
36
|
-
* 已成功的终态结果(不同 requestId);省略表示只按 requestId 去重。 */
|
|
37
|
-
readonly dedupe?: "payload";
|
|
38
|
-
validate(input: Record<string, unknown>): void;
|
|
39
|
-
run(input: Record<string, unknown>, ctx: {
|
|
40
|
-
signal: AbortSignal;
|
|
41
|
-
progress: (sequence: number, percent: number) => void;
|
|
42
|
-
requestId: string;
|
|
43
|
-
invoke?: Capability;
|
|
44
|
-
}): Promise<unknown>;
|
|
45
|
-
}
|
|
46
|
-
export interface RecordView {
|
|
47
|
-
requestId: string;
|
|
48
|
-
state: State;
|
|
49
|
-
sequence: number;
|
|
50
|
-
cancelRequested: boolean;
|
|
51
|
-
delivery: "pending" | "returned";
|
|
52
|
-
result?: unknown;
|
|
53
|
-
error?: string;
|
|
54
|
-
progress?: number;
|
|
55
|
-
/** true 表示本次调用附着到已存在的逻辑执行,而不是新建执行(0.11.0 新增,可选)。 */
|
|
56
|
-
reused?: true;
|
|
57
|
-
}
|
|
58
|
-
export declare function object(v: unknown): Record<string, unknown>;
|
|
59
|
-
/** 规范排序后的稳定摘要,只用于同 requestId 的冲突比较,不用于跨请求去重。 */
|
|
60
|
-
export declare function canonical(v: unknown): string;
|
|
61
|
-
export declare function parse(raw: unknown): Message;
|
|
62
|
-
export declare function freezeJson<T>(value: T): T;
|
package/dist/protocol.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { assertJson } from "./json.js";
|
|
2
|
-
import { ERRORS } from "./error-codes.js";
|
|
3
|
-
import { LIMITS } from "./limits.js";
|
|
4
|
-
export function object(v) {
|
|
5
|
-
if (!v || typeof v !== "object" || Array.isArray(v))
|
|
6
|
-
throw Error(ERRORS.INVALID_OBJECT);
|
|
7
|
-
return v;
|
|
8
|
-
}
|
|
9
|
-
/** 规范排序后的稳定摘要,只用于同 requestId 的冲突比较,不用于跨请求去重。 */
|
|
10
|
-
export function canonical(v) {
|
|
11
|
-
if (v === null || typeof v !== "object")
|
|
12
|
-
return JSON.stringify(v);
|
|
13
|
-
if (Array.isArray(v))
|
|
14
|
-
return "[" + v.map(canonical).join(",") + "]";
|
|
15
|
-
return ("{" +
|
|
16
|
-
Object.keys(v)
|
|
17
|
-
.sort()
|
|
18
|
-
.map((k) => JSON.stringify(k) +
|
|
19
|
-
":" +
|
|
20
|
-
canonical(v[k]))
|
|
21
|
-
.join(",") +
|
|
22
|
-
"}");
|
|
23
|
-
}
|
|
24
|
-
export function parse(raw) {
|
|
25
|
-
assertJson(raw);
|
|
26
|
-
const m = object(raw);
|
|
27
|
-
if (Object.keys(m).some((k) => ![
|
|
28
|
-
"protocolVersion",
|
|
29
|
-
"messageId",
|
|
30
|
-
"requestId",
|
|
31
|
-
"type",
|
|
32
|
-
"payload",
|
|
33
|
-
].includes(k)))
|
|
34
|
-
throw Error(ERRORS.UNKNOWN_FIELD);
|
|
35
|
-
if (m.protocolVersion !== 1)
|
|
36
|
-
throw Error(ERRORS.UNSUPPORTED_VERSION);
|
|
37
|
-
for (const k of ["messageId", "requestId"])
|
|
38
|
-
if (typeof m[k] !== "string" || !LIMITS.idPattern.test(m[k]))
|
|
39
|
-
throw Error(ERRORS.INVALID_ID);
|
|
40
|
-
if (!["request", "status", "result", "cancel"].includes(m.type))
|
|
41
|
-
throw Error(ERRORS.UNSUPPORTED_TYPE);
|
|
42
|
-
object(m.payload);
|
|
43
|
-
if (Buffer.byteLength(JSON.stringify(m)) > LIMITS.messageMaxBytes)
|
|
44
|
-
throw Error(ERRORS.MESSAGE_TOO_LARGE);
|
|
45
|
-
return structuredClone(m);
|
|
46
|
-
}
|
|
47
|
-
export function freezeJson(value) {
|
|
48
|
-
if (value && typeof value === "object") {
|
|
49
|
-
for (const child of Object.values(value))
|
|
50
|
-
freezeJson(child);
|
|
51
|
-
Object.freeze(value);
|
|
52
|
-
}
|
|
53
|
-
return value;
|
|
54
|
-
}
|