forked from ChaiHao/BPOS-MVP
用户问:为什么编辑一个版本、保存就自动多一个副本?那不是我要的。
旧机制「保存恒新增版本号」改为:
- savePackage:pkg.version 已存在 → **就地写回该版**(号不变、状态不变);
`asNew: true`(新建按钮)或新流程首版才铸新版本号(服务端算,不生效)
- 底线三道,一道不少:
① **在途钉版不可变** —— 该版有未完结工作流(按 (包,版本) 钉定义)→ 409,
一字不落库;「就地覆盖会改掉在途正在读的编排」由这道闸守,不再靠只插不改一刀切
② **生效版必须始终可运行** —— 写回生效版跑闭合闸,不闭合 412 带整份报告;
未生效版画图不检查、随手存
③ **陈旧编辑不复活** —— 流程存在而版本号已被清理 → 409(实测:停在已删旧版上的
标签页发来保存,把老内容静默复活成了新版本;StaleVersionError 拦死)
- store:新增 updatePackageDefinition(只许命中现存版本)+ countPinnedInFlight
- 前端:保存按钮「保存 v{n}」;新建走 asNew;文案全线「新建才长版本」
- 测试:save-package.test 六例(写回/钉版/热改闭合/asNew/防复活/首版);
过程中揪出双 API 进程并存(旧进程霸端口跑旧代码)——已重启归一
实测:改名保存 → 版本列表仍唯一 v4 生效中,名字已写回;八例端到端全绿;
五闸退出码全过(api:check 提交后转绿)。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
125 lines
5.2 KiB
TypeScript
125 lines
5.2 KiB
TypeScript
/**
|
|
* module: process —— 本模块要外界提供的能力(编码规范 §10.1 / §5.3)。
|
|
*/
|
|
import type { ProcessPackage, StaffId, TerminalState, WorkflowState } from '@contracts';
|
|
import type { NodeInstance } from './internal/domain/owner-resolution.ts';
|
|
import type { ActivityContractFace } from './internal/domain/closure.ts';
|
|
|
|
export type Clock = { now(): Date };
|
|
export type IdGenerator = { next(): string };
|
|
|
|
/** 工作流实例的持久面 —— 崩溃后可续跑 */
|
|
export type WorkflowRecord = {
|
|
readonly id: string;
|
|
readonly packageId: string;
|
|
readonly packageVersion: number;
|
|
readonly subject: string;
|
|
readonly state: WorkflowState;
|
|
/** 来源:凡单必有来源(触发器 / 登记人 / 上游系统) */
|
|
readonly source: { kind: 'periodic' | 'event' | 'registration'; ref: string; by?: string };
|
|
readonly initiation: Record<string, unknown>;
|
|
/**
|
|
* 工作组绑定的**快照**(ADR-011):起单时按来源人装载,之后改组不影响这条单。
|
|
* 留痕要能解释「当时为什么派给他」,而不是被今天的组织调整改写(同 AM 9.1 版本信封)。
|
|
*/
|
|
readonly workGroup?: Record<string, string>;
|
|
/** 各节点输出口载荷 —— 边映射装配的来源 */
|
|
readonly ports: Record<string, Record<string, unknown>>;
|
|
readonly vars: Record<string, unknown>;
|
|
readonly startedAt: string;
|
|
readonly finishedAt?: string;
|
|
};
|
|
|
|
export type ProcessStore = {
|
|
savePackage(pkg: ProcessPackage): Promise<void>;
|
|
/** 就地写回一版的定义(编辑即其身)—— 撞不存在的版本报错,不静默插入 */
|
|
updatePackageDefinition(id: string, version: number, pkg: ProcessPackage): Promise<void>;
|
|
/** 钉在该版上的未完结工作流数 —— 在途钉版不可变的判据 */
|
|
countPinnedInFlight(id: string, version: number): Promise<number>;
|
|
/** 只改状态,不动定义 —— state 在列上与 definition 里各存一份,两处要一起改 */
|
|
setPackageState(id: string, version: number, state: 'active' | 'retired'): Promise<void>;
|
|
getPackage(id: string, version?: number): Promise<ProcessPackage | undefined>;
|
|
listPackages(): Promise<ProcessPackage[]>;
|
|
|
|
insertWorkflow(record: WorkflowRecord): Promise<void>;
|
|
getWorkflow(id: string): Promise<WorkflowRecord | undefined>;
|
|
listWorkflows(limit: number): Promise<WorkflowRecord[]>;
|
|
updateWorkflow(id: string, patch: Partial<WorkflowRecord>): Promise<WorkflowRecord>;
|
|
|
|
listInstances(workflowId: string): Promise<NodeInstance[]>;
|
|
insertInstance(workflowId: string, instance: NodeInstance & { taskId?: string; approvalId?: string }): Promise<void>;
|
|
updateInstance(
|
|
workflowId: string,
|
|
nodeId: string,
|
|
instance: number,
|
|
patch: Partial<NodeInstance> & { taskId?: string },
|
|
): Promise<void>;
|
|
findInstanceByTask(taskId: string): Promise<{ workflowId: string; nodeId: string; instance: number } | undefined>;
|
|
};
|
|
|
|
/** 活动契约面 —— app 注入 `activity-registry`(L4):编排校验与起单都要它 */
|
|
export type ActivityDirectory = {
|
|
faces(): Promise<Map<string, ActivityContractFace>>;
|
|
};
|
|
|
|
/** 岗位与在岗人员 —— app 注入 `org`(L1):负责人四策略解析的候选集 */
|
|
export type OrgDirectory = {
|
|
positions(): Promise<Set<string>>;
|
|
candidates(position: string): Promise<Array<{ staffId: string; name: string; openTasks: number }>>;
|
|
/** 某人的工作组绑定(ADR-011)—— 起单时按来源人取,取不到即不装载 */
|
|
workGroupBinding(staffId: string): Promise<Readonly<Record<string, string>> | undefined>;
|
|
/** 在岗与否 —— 绑定的人已离岗就不硬用,退回四策略 */
|
|
isActive(staffId: string): Promise<boolean>;
|
|
};
|
|
|
|
/** 起单与终态 —— app 注入 `task`(L6) */
|
|
export type TaskGateway = {
|
|
start(input: {
|
|
activityId: string;
|
|
ownerId: StaffId;
|
|
title: string;
|
|
workflowId: string;
|
|
nodeId: string;
|
|
data: Record<string, unknown>;
|
|
message?: string;
|
|
}): Promise<{ id: string }>;
|
|
};
|
|
|
|
/** 审批点 —— app 注入 `human-tool`(L3):审批单卡到审批人工位 */
|
|
export type ApprovalGateway = {
|
|
raise(input: {
|
|
workflowId: string;
|
|
nodeId: string;
|
|
approverId: StaffId;
|
|
subject: string;
|
|
basis: ReadonlyArray<{ k: string; v: string }>;
|
|
}): Promise<{ id: string }>;
|
|
};
|
|
|
|
/**
|
|
* 调用接口的入参校验 —— app 注入 ajv。
|
|
* 「凡单必有来源」的另一半是「凡单必合契约」:不合契约**不得起单**,
|
|
* 且必须在**建工作流之前**判掉,否则会留下一条永远推不动的在途单。
|
|
*/
|
|
export type SchemaValidator = {
|
|
validate(schema: Record<string, unknown>, value: unknown): { ok: boolean; errors: string[] };
|
|
};
|
|
|
|
/** S-FEEL —— app 注入 `@sfeel`:流转零 LLM */
|
|
export type Sfeel = {
|
|
condition(expression: string, scope: Readonly<Record<string, unknown>>): boolean;
|
|
expression(expression: string, scope: Readonly<Record<string, unknown>>): unknown;
|
|
};
|
|
|
|
/** 流转记入事件 —— app 注入 `event`(L1) */
|
|
export type FlowEventPublisher = {
|
|
publish(input: { workflowId: string; kind: string; detail: Record<string, unknown> }): Promise<void>;
|
|
};
|
|
|
|
/** 终态回执 —— 登记人收消息 */
|
|
export type ReceiptNotifier = {
|
|
notify(input: { to: StaffId; workflowId: string; subject: string; state: WorkflowState }): Promise<void>;
|
|
};
|
|
|
|
export type { TerminalState };
|