@mldong/jeeflow 1.8.33 → 1.8.35

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/engine.d.ts CHANGED
@@ -15,6 +15,15 @@ export declare const KeyProcessStartNextNodeOperator = "f_nextNodeOperator";
15
15
  export declare const KeyAutoExecute = "flow.auto";
16
16
  export declare const KeyAdminID = "flow.admin";
17
17
  export declare const KeyAutoGenTitle = "autoGenTitle";
18
+ export declare const KeyCcActorsStart = "f_ccActors";
19
+ export declare const KeyCcActors = "tf_ccActors";
20
+ /**
21
+ * issues/127:抄送人入参归一(判据对齐 Java `JeeflowEngineImpl.handleCcActors`)——
22
+ * 数组或逗号串都吃,逐项 trim、丢空项、按出现顺序去重。
23
+ * 去重不是锦上添花:`createCcInstance` 逐行 INSERT,内存仓那侧还按实例去重,
24
+ * 同一人写两次会"一行两事件",破掉 §11.3「逐抄送人 fire 一次 = cc 行粒度一一对应」。
25
+ */
26
+ export declare function parseCcActors(v: any): string[];
18
27
  export interface Engine {
19
28
  startProcessInstanceById(defineId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
20
29
  executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
@@ -84,6 +93,29 @@ export declare class EngineImpl implements Engine {
84
93
  evalExpr(expr: string, vars: Record<string, any>): Promise<any>;
85
94
  private firePost;
86
95
  fireEvent(evt: ProcessEvent): Promise<void>;
96
+ /**
97
+ * issues/127 / 规范 11 §11.7:抄送落库 + 逐抄送人 fire CC_CREATE(4) 的**唯一漏斗**。
98
+ * 行为基准=Java `JeeflowEngineImpl.handleCcActors` + `notifyCcCreate`:
99
+ * ① 先 `createCcInstance`(cc 行 INSERT 落库)② 再按 cc 行粒度逐人 fire,
100
+ * ccActorId 直传事件体(监听器免反查 cc 表)。
101
+ * 三条路径(发起 f_ccActors/办理 tf_ccActors/手动 processInstance/createCCInstance)
102
+ * 都走本函数 ⇒ §11.2 原则 1「同一事实只发一次、路径不进事件名」;入参为空零副作用。
103
+ */
104
+ handleCcActors(instanceId: string, operator: string, ccActors: any): Promise<string[]>;
105
+ /**
106
+ * 规范 11 §11.3 code 2/9 的 fire 漏斗——**必须在实例 state 落库之后调用**(§11.2 原则 3)。
107
+ * 只服务「流程自己走到终点」这一事实:办结(20)/拒绝到终态(45) 共用 PROCESS_INSTANCE_END(2),
108
+ * 靠载荷 state 分(§11.6:实例终态=2,旧版 Finish/Reject 拆分作废);
109
+ * state=40 那一档额外 fire INSTANCE_TERMINATED(9)(规范 08 场景 34)。
110
+ *
111
+ * ⚠️ 撤回(30) **不走本漏斗**——规范 11 §11.3 码 2/8 与场景 32/34 明写「撤回(30)/终止(40)
112
+ * 不发 2,各发 8/9」,同轮既发 8 又发 2 ⇒ 下游收到「流程已办结」的错通知(node 首版即此形状,已纠)。
113
+ *
114
+ * ⚠️ 本栈当前**没有任何写 40 的门面动作**(spec 06 无 processInstance/terminate 档;
115
+ * InstanceState.Interrupt 仅定义、零赋值点),故 code 9 只有经本漏斗才会发得出——
116
+ * 接线是为将来终止腿落地时不再漏发,不是给现有路径凭空多发事件。
117
+ */
118
+ notifyInstanceEnd(inst: ProcessInstance, operator: string, reason?: string): Promise<void>;
87
119
  startProcessInstanceById(defineId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
88
120
  executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
89
121
  executeAndJumpToEnd(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
package/dist/engine.js CHANGED
@@ -1,4 +1,4 @@
1
- import { TypeStart, TypeEnd, TypeTask, TypeDecision, TypeFork, TypeJoin, TypeCustom, ProcessInstance, TaskState, SubmitType, } from './model.js';
1
+ import { TypeStart, TypeEnd, TypeTask, TypeDecision, TypeFork, TypeJoin, TypeCustom, ProcessInstance, InstanceState, TaskState, SubmitType, } from './model.js';
2
2
  import { EventType } from './extensions.js';
3
3
  export const KeySubmitType = 'submitType';
4
4
  export const KeyBusinessNo = 'BUSINESS_NO';
@@ -17,6 +17,51 @@ export const KeyAutoExecute = 'flow.auto';
17
17
  export const KeyAdminID = 'flow.admin';
18
18
  // issue 29:自动生成标题(对齐 boot3 FlowConst.AUTO_GEN_TITLE)
19
19
  export const KeyAutoGenTitle = 'autoGenTitle';
20
+ // issues/127:抄送人入参两枚(逐字对齐 Java FlowConst.CC_ACTORS_START / CC_ACTORS)
21
+ // f_ccActors 发起时抄送 tf_ccActors 办理时抄送
22
+ export const KeyCcActorsStart = 'f_ccActors';
23
+ export const KeyCcActors = 'tf_ccActors';
24
+ /**
25
+ * issues/127:抄送人入参归一(判据对齐 Java `JeeflowEngineImpl.handleCcActors`)——
26
+ * 数组或逗号串都吃,逐项 trim、丢空项、按出现顺序去重。
27
+ * 去重不是锦上添花:`createCcInstance` 逐行 INSERT,内存仓那侧还按实例去重,
28
+ * 同一人写两次会"一行两事件",破掉 §11.3「逐抄送人 fire 一次 = cc 行粒度一一对应」。
29
+ */
30
+ export function parseCcActors(v) {
31
+ const list = Array.isArray(v) ? v : (typeof v === 'string' ? v.split(',') : []);
32
+ const out = [];
33
+ const seen = new Set();
34
+ for (const raw of list) {
35
+ const s = String(raw ?? '').trim();
36
+ if (!s || seen.has(s))
37
+ continue;
38
+ seen.add(s);
39
+ out.push(s);
40
+ }
41
+ return out;
42
+ }
43
+ /**
44
+ * 规范 11 §11.3 载荷键 submitType 归一:出**整数**,不用 undefined(⇒ 省略整键)表达
45
+ * (issues/122 同族坑)。缺省/非法时取引擎既有默认——不认 submitType 的动作一律按同意办
46
+ * (executeNode TypeEnd 分支同样是"非 Reject 即办结"),所以归一成 1(AGREE) 与实际行为一致。
47
+ */
48
+ function normalizeSubmitType(v) {
49
+ const n = Number(v);
50
+ return Number.isFinite(n) ? n : SubmitType.Agree;
51
+ }
52
+ /**
53
+ * 规范 11 §11.3 code 5/6 互斥判据(场景 30/31「走退回的这一次不得再发 5」)。
54
+ * 退回族=2 拒绝 / 3 退回上一步 / 6 退回发起人 / 20 会签软拒绝;
55
+ * 其余(0 APPLY / 1 AGREE / 4 JUMP / 5 重新提交 / 常规会签办理)算"任务被办掉"。
56
+ * ⚠️ 4(JUMP) 按 §11.3 code 5 那一行的"跳转"归 complete:本栈分不出前跳/回跳
57
+ * (要判拓扑),而 §11.3 code 6 的"跳转回退"在 boot2 血缘语义下就是 submitType=3。
58
+ */
59
+ function isRejectSubmitType(submitType) {
60
+ return submitType === SubmitType.Reject
61
+ || submitType === SubmitType.Rollback
62
+ || submitType === SubmitType.RollbackToOperator
63
+ || submitType === SubmitType.CountersignDisagree;
64
+ }
20
65
  /**
21
66
  * 照 mldong-boot2 NodeModel.canRejected:自 current 的入边回溯,命中 parent 放行;
22
67
  * 入边来源是 fork/join/start 时**跳过该条入边、不再深入**(boot2 是 continue,不是穿越),
@@ -197,16 +242,19 @@ export class EngineImpl {
197
242
  await ic.postHandle(node, inst);
198
243
  }
199
244
  async fireEvent(evt) {
200
- // 公开事件发布入口(issues/102 CC_CREATE):facade 层 CC 实例创建后逐抄送人 fire;
245
+ // 公开事件发布入口(issues/102 CC_CREATE,issues/127/132 全码表):引擎内部与各条 fire 腿共用;
201
246
  // 无监听器(ext/listeners 为空)时零副作用,与上一版逐字节一致
202
247
  await this.#fireEvent(evt);
203
248
  }
204
249
  async #fireEvent(evt) {
205
- if (!this.ext?.listeners)
250
+ const listeners = this.ext?.listeners;
251
+ // 零注册安全返回(§11.5「无监听器」义务:不得空指针/抛错)——ext 未设、listeners 未给、
252
+ // 给了空数组三种形态都走这里,非数组的脏注入同样不炸主流程
253
+ if (!Array.isArray(listeners) || listeners.length === 0)
206
254
  return;
207
- // 兜底语义(issues/104 P2 统一口径):单监听器异常只记录不传播——
208
- // 不得影响引擎主流程,也不得中断后续监听器(对齐 PHP per-listener catch)
209
- for (const l of this.ext.listeners) {
255
+ // 兜底语义(issues/104 P2 / §11.5 异常隔离):**逐监听器** catch——单个监听器抛异常只记日志,
256
+ // ① 不回滚主流程 ② 不中断后续监听器(对齐 PHP per-listener catch;同步抛错也被 await 捕获)
257
+ for (const l of listeners) {
210
258
  try {
211
259
  await l(evt);
212
260
  }
@@ -215,6 +263,44 @@ export class EngineImpl {
215
263
  }
216
264
  }
217
265
  }
266
+ /**
267
+ * issues/127 / 规范 11 §11.7:抄送落库 + 逐抄送人 fire CC_CREATE(4) 的**唯一漏斗**。
268
+ * 行为基准=Java `JeeflowEngineImpl.handleCcActors` + `notifyCcCreate`:
269
+ * ① 先 `createCcInstance`(cc 行 INSERT 落库)② 再按 cc 行粒度逐人 fire,
270
+ * ccActorId 直传事件体(监听器免反查 cc 表)。
271
+ * 三条路径(发起 f_ccActors/办理 tf_ccActors/手动 processInstance/createCCInstance)
272
+ * 都走本函数 ⇒ §11.2 原则 1「同一事实只发一次、路径不进事件名」;入参为空零副作用。
273
+ */
274
+ async handleCcActors(instanceId, operator, ccActors) {
275
+ const actors = parseCcActors(ccActors);
276
+ if (!actors.length || !instanceId)
277
+ return actors;
278
+ await this.repo.createCcInstance(instanceId, operator, ...actors);
279
+ for (const ccActorId of actors) {
280
+ await this.fireEvent({ type: EventType.CcCreate, instanceId, operator, ccActorId });
281
+ }
282
+ return actors;
283
+ }
284
+ /**
285
+ * 规范 11 §11.3 code 2/9 的 fire 漏斗——**必须在实例 state 落库之后调用**(§11.2 原则 3)。
286
+ * 只服务「流程自己走到终点」这一事实:办结(20)/拒绝到终态(45) 共用 PROCESS_INSTANCE_END(2),
287
+ * 靠载荷 state 分(§11.6:实例终态=2,旧版 Finish/Reject 拆分作废);
288
+ * state=40 那一档额外 fire INSTANCE_TERMINATED(9)(规范 08 场景 34)。
289
+ *
290
+ * ⚠️ 撤回(30) **不走本漏斗**——规范 11 §11.3 码 2/8 与场景 32/34 明写「撤回(30)/终止(40)
291
+ * 不发 2,各发 8/9」,同轮既发 8 又发 2 ⇒ 下游收到「流程已办结」的错通知(node 首版即此形状,已纠)。
292
+ *
293
+ * ⚠️ 本栈当前**没有任何写 40 的门面动作**(spec 06 无 processInstance/terminate 档;
294
+ * InstanceState.Interrupt 仅定义、零赋值点),故 code 9 只有经本漏斗才会发得出——
295
+ * 接线是为将来终止腿落地时不再漏发,不是给现有路径凭空多发事件。
296
+ */
297
+ async notifyInstanceEnd(inst, operator, reason = '') {
298
+ const state = Number(inst.state);
299
+ await this.fireEvent({ type: EventType.ProcessInstanceEnd, instanceId: inst.id, operator, state });
300
+ if (state === InstanceState.Interrupt) {
301
+ await this.fireEvent({ type: EventType.InstanceTerminated, instanceId: inst.id, operator, reason });
302
+ }
303
+ }
218
304
  // ─── Start ─────────────────────────────────────────────────────────────────
219
305
  async startProcessInstanceById(defineId, operator, args = {}) {
220
306
  const def = await this.repo.findDefineById(defineId);
@@ -229,7 +315,8 @@ export class EngineImpl {
229
315
  // 聚合根工厂创建实例
230
316
  const inst = ProcessInstance.create(this.nextId(), defineId, operator, vars, now);
231
317
  await this.repo.saveInstance(inst);
232
- await this.fireEvent({ type: EventType.ProcessStart, instanceId: inst.id, operator });
318
+ // §11.3 code 1:实例行 insert **之后** fire(场景 28:发起前先 fire ⇒ 红)
319
+ await this.fireEvent({ type: EventType.ProcessInstanceStart, instanceId: inst.id, operator });
233
320
  const startNode = findNodeByType(flow, TypeStart);
234
321
  if (!startNode)
235
322
  throw new Error('no start node');
@@ -241,6 +328,15 @@ export class EngineImpl {
241
328
  // ─── Execute ───────────────────────────────────────────────────────────────
242
329
  async executeProcessTask(taskId, operator, args = {}) {
243
330
  const { task, inst, flow, vars } = await this.prepareExecuteTask(taskId, operator, args);
331
+ // issues/127 / 规范 11 §11.7「办理时抄送」腿的统一出口:任务更新已在 prepareExecuteTask
332
+ // 落库,此处建 cc 行并逐人 fire CC_CREATE(4),再回读实例。
333
+ // 基准=Java JeeflowEngineImpl.executeProcessTask(node.execute 之后 handleCcActors、
334
+ // 然后 persistTasks)——**每条返回路径都执行**,含会签"未完成即停留"的提前返回,
335
+ // Java 那侧 handleCcActors 同样在这些路径上会跑到。
336
+ const finishExecute = async () => {
337
+ await this.handleCcActors(inst.id, operator, args[KeyCcActors]);
338
+ return (await this.repo.findInstanceById(inst.id));
339
+ };
244
340
  const now = new Date();
245
341
  const curNode = findNode(flow, task.taskName);
246
342
  if (curNode) {
@@ -279,19 +375,19 @@ export class EngineImpl {
279
375
  // 变量源=实例变量(与建单同档),取时基准=本行 createTime 用的同一个 now。
280
376
  applyNodeExpireTime(nt, curNode.properties?.expireTime, inst.variables, now);
281
377
  await this.repo.saveTask(nt);
282
- // TASK_CREATE:顺序会签推进新任务落库后 fire(对齐 Java CreateTaskHandler / Rust)
283
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: curNode.id, operator });
284
- return (await this.repo.findInstanceById(inst.id));
378
+ // PROCESS_TASK_START:顺序会签推进新任务落库后 fire(对齐 Java CreateTaskHandler / Rust)
379
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: curNode.id, operator, actors: [...nt.actorIds] });
380
+ return finishExecute();
285
381
  }
286
382
  }
287
383
  else {
288
- return (await this.repo.findInstanceById(inst.id));
384
+ return finishExecute();
289
385
  }
290
386
  }
291
387
  if ((ct === 'PARALLEL' || ct?.startsWith('RATIO')) && !csVeto) {
292
388
  const doing = await this.repo.findDoingTasks(inst.id);
293
389
  if (doing.length > 0)
294
- return (await this.repo.findInstanceById(inst.id));
390
+ return finishExecute();
295
391
  }
296
392
  // issues/91:会签节点 merged 后(ONE_VOTE_VETO 否决 / 全部完成任一路径),
297
393
  // 废弃该节点剩余 DOING 任务(对齐内置引擎 abandonProcessTask):
@@ -311,7 +407,7 @@ export class EngineImpl {
311
407
  await this.executeNode(flow, inst, node, operator, vars, task.id);
312
408
  }
313
409
  }
314
- return (await this.repo.findInstanceById(inst.id));
410
+ return finishExecute();
315
411
  }
316
412
  // ─── Reject ────────────────────────────────────────────────────────────────
317
413
  async executeAndJumpToEnd(taskId, operator, args = {}) {
@@ -319,7 +415,9 @@ export class EngineImpl {
319
415
  // 门面 submitType=2 REJECT 唯一入口(对齐 Java executeAndJumpToEnd 语义)
320
416
  inst.reject(new Date());
321
417
  await this.repo.updateInstance(inst);
322
- await this.fireEvent({ type: EventType.ProcessReject, instanceId: inst.id, taskId, operator });
418
+ // §11.3 code 2:拒绝也是"实例进入终态"(state=45 落库后 fire,靠载荷 state 与办结分家);
419
+ // "任务被退回"这一事实另由 prepareExecuteTask 的 TASK_REJECT(6) 承载(场景 31/32 两支并存)
420
+ await this.notifyInstanceEnd(inst, operator);
323
421
  return (await this.repo.findInstanceById(inst.id));
324
422
  }
325
423
  // ─── Jump(ROLLBACK 空 target / JUMP 命名 target,boot2 executeAndJumpTask)────
@@ -379,16 +477,24 @@ export class EngineImpl {
379
477
  const vars = { ...baseVars, ...task.variables, ...args };
380
478
  await this.addUserInfo(operator, vars);
381
479
  const now = new Date();
480
+ // §11.2 原则 2「码粗、载荷细」+场景 30/31 互斥:本次动作是"办掉"还是"退回"由 submitType 定,
481
+ // 同一动作只发其中一支(旧形状无论 submitType 一律 fire TaskComplete 即本案病灶)
482
+ const submitType = normalizeSubmitType(vars[KeySubmitType]);
382
483
  // 聚合根:完成任务(子实体状态转换 + 实例变量合并)
383
484
  inst.completeTask(task, operator, vars, now);
384
485
  await this.repo.updateTask(task);
385
486
  // v1.0.1:updateInstance 级联持久化依赖聚合内任务副本为最新状态,
386
487
  // completeTask 改的是外部任务对象,需同步回聚合根
387
488
  syncTaskToAggregate(inst, task);
388
- await this.fireEvent({ type: EventType.TaskComplete, instanceId: inst.id, taskId: task.id, nodeId: task.taskName, operator });
389
489
  // issues/97:实例变量写回排除操作人 u_*,保留 start 注入的发起人 u_*(u_realName 恒为发起人)
390
490
  inst.variables = mergeExecIntoInstance(baseVars, vars);
391
491
  await this.repo.updateInstance(inst);
492
+ // §11.2 原则 3:任务行与实例**都落库之后**才 fire(旧形状排在 updateInstance 之前,
493
+ // 监听器反查实例读到旧状态——与 issues/121/126 两轮"回写序"同族)
494
+ await this.fireEvent({
495
+ type: isRejectSubmitType(submitType) ? EventType.TaskReject : EventType.TaskComplete,
496
+ instanceId: inst.id, taskId: task.id, nodeId: task.taskName, operator, submitType,
497
+ });
392
498
  return { task, inst, flow, vars };
393
499
  }
394
500
  // 是否 start 直接后继任务节点(issues/79 对齐 Java FlowUtil.isFirstTaskName)
@@ -435,8 +541,8 @@ export class EngineImpl {
435
541
  if (eff.length > 1)
436
542
  nt.actorIds = eff;
437
543
  await this.repo.saveTask(nt);
438
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id,
439
- taskId: nt.id, nodeId: prev.id, operator });
544
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id,
545
+ taskId: nt.id, nodeId: prev.id, operator, actors: [...nt.actorIds] });
440
546
  }
441
547
  /**
442
548
  * issues/116:对每个参与人查一次生效委托(判据在仓储侧:空 processName 全流程兜底 /
@@ -487,7 +593,7 @@ export class EngineImpl {
487
593
  nt.actorIds = eff;
488
594
  applyNodeExpireTime(nt, expireExpr, expireArgs, now);
489
595
  await this.repo.saveTask(nt);
490
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
596
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
491
597
  }
492
598
  return;
493
599
  case 'SEQUENTIAL': {
@@ -502,7 +608,7 @@ export class EngineImpl {
502
608
  nt.actorIds = eff;
503
609
  applyNodeExpireTime(nt, expireExpr, expireArgs, now);
504
610
  await this.repo.saveTask(nt);
505
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
611
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
506
612
  return;
507
613
  }
508
614
  default:
@@ -513,7 +619,7 @@ export class EngineImpl {
513
619
  nt.actorIds = eff;
514
620
  applyNodeExpireTime(nt, expireExpr, expireArgs, now);
515
621
  await this.repo.saveTask(nt);
516
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
622
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
517
623
  }
518
624
  return;
519
625
  }
@@ -524,7 +630,7 @@ export class EngineImpl {
524
630
  nt.actorIds = effActors;
525
631
  applyNodeExpireTime(nt, expireExpr, expireArgs, now);
526
632
  await this.repo.saveTask(nt);
527
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
633
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
528
634
  }
529
635
  // ─── Helpers ───────────────────────────────────────────────────────────────
530
636
  async loadAndCheck(taskId, operator) {
@@ -576,7 +682,8 @@ export class EngineImpl {
576
682
  // issues/97:结束节点写回同样排除操作人 u_*(保留发起人 u_*,与 prepareExecuteTask 一致)
577
683
  inst.variables = mergeExecIntoInstance(inst.variables, vars);
578
684
  await this.repo.updateInstance(inst);
579
- await this.fireEvent({ type: EventType.ProcessFinish, instanceId: inst.id, operator });
685
+ // §11.3 code 2:办结(20)/拒绝(45) 共用 PROCESS_INSTANCE_END,state 落库后 fire(§11.6)
686
+ await this.notifyInstanceEnd(inst, operator);
580
687
  return;
581
688
  }
582
689
  }
@@ -665,8 +772,8 @@ export class EngineImpl {
665
772
  nt.actorIds = eff;
666
773
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 并行会签全员
667
774
  await this.repo.saveTask(nt);
668
- // TASK_CREATE:任务落库后逐个 fire(会签多任务逐个,对齐 Java CreateTaskHandler)
669
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
775
+ // PROCESS_TASK_START:任务落库后逐个 fire(会签多任务逐个,对齐 Java CreateTaskHandler)
776
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
670
777
  }
671
778
  return;
672
779
  case 'SEQUENTIAL': {
@@ -683,7 +790,7 @@ export class EngineImpl {
683
790
  nt.actorIds = eff;
684
791
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 串行会签首位成员
685
792
  await this.repo.saveTask(nt);
686
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
793
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
687
794
  return;
688
795
  }
689
796
  default:
@@ -694,7 +801,7 @@ export class EngineImpl {
694
801
  nt.actorIds = eff;
695
802
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 未配会签类型=全员预创建,与并行同档
696
803
  await this.repo.saveTask(nt);
697
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
804
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
698
805
  }
699
806
  return;
700
807
  }
@@ -706,7 +813,7 @@ export class EngineImpl {
706
813
  nt.actorIds = effActors;
707
814
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 普通建单
708
815
  await this.repo.saveTask(nt);
709
- await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
816
+ await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
710
817
  }
711
818
  async resolveActors(node, inst, operator, vars) {
712
819
  // 1a. Registry 按名称解析(推荐)
@@ -17,14 +17,83 @@ export type AssignmentHandler = (handlerName: string, node: FlowNode, inst: Proc
17
17
  * @returns 选中的分支边 ID(空字符串表示不处理)
18
18
  */
19
19
  export type DecisionHandler = (handlerName: string, node: FlowNode, inst: ProcessInstance, vars: Record<string, any>) => string | Promise<string>;
20
+ /**
21
+ * 流程事件类型 —— **规范 11 §11.3「A 套整型码表」**(issues/132 整表重排 + issues/127 补 5/6/7/8/9)。
22
+ *
23
+ * ⚠️ 破坏性变更(spec §11.6 明写):本栈旧形状是 `iota` 起的 0..5 套
24
+ * (ProcessStart=0 / ProcessFinish=1 / ProcessReject=2 / TaskCreate=3 / TaskComplete=4 / CcCreate=5),
25
+ * 现整表重排到 A 套 1..9,与 Java/PHP/Rust/MoonBit/C# 同套:
26
+ * - CcCreate 5 → 4(4 号位由 Java 让出的死码 PROCESS_TASK_END 腾出,与 PHP v1.3.8 活码对齐)
27
+ * - TaskComplete 4 → 5
28
+ * - 旧 ProcessFinish(1) 与 ProcessReject(2) **合并**为 ProcessInstanceEnd(2)——办结/拒绝/撤回/终止
29
+ * 共用一支,靠载荷 `state` 分;"任务被退回"另立 TaskReject(6),不再混在实例终态里
30
+ * - TaskCreate → ProcessTaskStart(规范名)、ProcessStart → ProcessInstanceStart
31
+ *
32
+ * **规范名是权威,码值只是各栈内部的附带数值**(§11.3 首段):集成层跨语言判据一律按规范名分派,
33
+ * 不得拿数字码当判据(旧版已发布版本里数字码不可混用)。10+ 号段为超时催办/超时自动通过预留,
34
+ * 本轮不发(§11.4 第 1 条:八栈都无时钟扫描器,发了没有触发源)。
35
+ *
36
+ * 旧成员名(`ProcessStart`/`ProcessFinish`/`ProcessReject`/`TaskCreate`/`TaskComplete`/`CcCreate`)
37
+ * 按 §11.6「改名兼容义务」**保留一代**——别名在本 enum **外部**,见下方常量块(为什么不能写进来)。
38
+ */
20
39
  export declare enum EventType {
21
- ProcessStart = 0,
22
- ProcessFinish = 1,
23
- ProcessReject = 2,
24
- TaskCreate = 3,
25
- TaskComplete = 4,
26
- CcCreate = 5
40
+ /** 1 · 实例发起成功——实例行 `insert` 之后 fire */
41
+ ProcessInstanceStart = 1,
42
+ /** 2 · 实例进入终态——`state` 落库为 20/30/40/45/50/99 之后 fire,载荷带落库后的 `state` */
43
+ ProcessInstanceEnd = 2,
44
+ /** 3 · 新待办生成——每个任务行落库(分到 taskId)之后逐任务 fire,载荷带 `actors` */
45
+ ProcessTaskStart = 3,
46
+ /** 4 · 新增一条抄送记录——cc 行落库之后**逐抄送人** fire(发起 f_ccActors/办理 tf_ccActors/手动 createCCInstance 三条路径同判) */
47
+ CcCreate = 4,
48
+ /** 5 · 任务被办掉(同意/跳转/会签办理)——任务行 state 更新为已完成并落库之后;与 6 互斥 */
49
+ TaskComplete = 5,
50
+ /** 6 · 任务被退回/拒绝(含退发起人、软拒绝、跳转回退)——退回动作使任务/实例落库之后;与 5 互斥 */
51
+ TaskReject = 6,
52
+ /** 7 · 转办发生——任务参与者被替换并落库之后 */
53
+ TaskTransfer = 7,
54
+ /** 8 · 撤回发生——撤回把实例 state 写 30 落库、被撤回任务行更新完成后 fire **一次**(不逐任务) */
55
+ TaskWithdraw = 8,
56
+ /** 9 · 实例被终止——实例 state 写 40 落库之后(本栈当前无写 40 的门面动作,见 engine.notifyInstanceEnd) */
57
+ InstanceTerminated = 9
27
58
  }
59
+ /**
60
+ * 旧成员名兼容别名 —— 规范 11 §11.6「改名兼容义务(八栈统一)」:成员改名时必须**保留旧成员名作为
61
+ * 同符号别名一代**并打 deprecate 注释,下一个代次再删。别名保的是"源码还能编过、switch 还能命中同一支",
62
+ * **不保数值**——本轮整表重排后旧码值已挪位,每条注释按「旧码 → 新码」标注(go 的
63
+ * `EventProcessStart = EventProcessInstanceStart` 即同形状;python 靠枚举成员别名做到"别名不参与
64
+ * list(EventType)",TS 数字枚举没有这个对应物,见下)。
65
+ *
66
+ * ⚠️ **TS 专有的坑(务必不要"顺手改优雅")**:这些别名必须写在 enum **外部**,绝不能写成 `enum`
67
+ * 的成员(`enum EventType { ProcessStart = 1, ProcessInstanceStart = 1, … }`)。数字枚举会为
68
+ * **每个**成员生成反向映射 `E[E["X"]=1]="X"`,同值的后声明成员会**覆盖** `E[1]` —— `EventType[1]`
69
+ * 就从 `'ProcessInstanceStart'` 变成 `'ProcessStart'`。集成层/L2-30 的事件流水 sink 靠 code→规范名
70
+ * 映射写 `<code>|<规范名>|<sourceId>`,反向映射被污染=线上假红。写成模块级常量则完全不进 `EventType`
71
+ * 对象:1..9 的反向映射与 `Object.keys(EventType)` 保持九支纯净(`__tests__/spec.test.ts` 的
72
+ * 「反向映射未被别名污染」格钉这条),别名只是同名同值的导出常量。
73
+ *
74
+ * 集成壳本轮一律**改用规范名**,不依赖别名续命(§11.6 末段)——别名只留给外部消费者一个代次的迁移窗口。
75
+ * §11.6 的"一代"窗口到期后,本块六条别名连同注释一并删除。
76
+ */
77
+ /** @deprecated 旧名(码 0)→ 规范名 `EventType.ProcessInstanceStart`(码 1):同一支,仅码值挪位。一代后删。 */
78
+ export declare const ProcessStart = EventType.ProcessInstanceStart;
79
+ /** @deprecated 旧名(码 1)→ 规范名 `EventType.ProcessInstanceEnd`(码 2):旧"办结"并入"实例终态",靠载荷 `state` 分。一代后删。 */
80
+ export declare const ProcessFinish = EventType.ProcessInstanceEnd;
81
+ /** @deprecated 旧名(码 2)→ 规范名 `EventType.ProcessInstanceEnd`(码 2):与 `ProcessFinish` **合并为同一支**(同码同物);"任务被退回"另立 `EventType.TaskReject`(6)。一代后删。 */
82
+ export declare const ProcessReject = EventType.ProcessInstanceEnd;
83
+ /** @deprecated 旧名(码 3)→ 规范名 `EventType.ProcessTaskStart`(码 3):名改码不改。一代后删。 */
84
+ export declare const TaskCreate = EventType.ProcessTaskStart;
85
+ /** @deprecated 旧名(码 4)→ 成员名沿用规范名 `EventType.TaskComplete`,但码值 4→5 挪位。此处导出的是"裸名"通道(`import { TaskComplete }`),一代后删。 */
86
+ export declare const TaskComplete = EventType.TaskComplete;
87
+ /** @deprecated 旧名(码 5)→ 成员名沿用规范名 `EventType.CcCreate`,但码值 5→4 挪位。同上,"裸名"通道,一代后删。 */
88
+ export declare const CcCreate = EventType.CcCreate;
89
+ /**
90
+ * 流程事件载荷(§11.3「直传载荷键」)。本栈用扁平键承载(Java 是 `ProcessEvent{eventType, sourceId,
91
+ * ccActorId, data}` 的 map 形状,§11.3 允许各栈自定承载形态,但**必备键必须拿得到**,键名 camelCase)。
92
+ *
93
+ * ⚠️ issues/122 同族坑:可空字段**不要用"省略整键"表达**。某支事件的必备键在 fire 点必须赋实际值
94
+ * (整数就出整数、字符串就出字符串),不得留 undefined ——undefined 经 JSON 序列化即整键消失,
95
+ * 与 NestJS 全局 SmartNullStripping 剥 null 键是同一个病。不适用某键的事件型别省它,直接不传即可。
96
+ */
28
97
  export interface ProcessEvent {
29
98
  type: EventType;
30
99
  instanceId: string;
@@ -33,6 +102,18 @@ export interface ProcessEvent {
33
102
  operator: string;
34
103
  /** 抄送人 id 直传事件体,监听器免反查 cc 表(issues/102;对齐 Java ccActorId / Go CcActorID) */
35
104
  ccActorId?: string;
105
+ /** code 2 · 落库后的实例状态整数(InstanceState:20/30/40/45/50/99) */
106
+ state?: number;
107
+ /** code 3 · 该待办的参与者列表(含并入的代理人) */
108
+ actors?: string[];
109
+ /** code 5 / 6 · 本次提交的 submitType(§11.2 原则 2「码粗、载荷细」:拒绝/跳转/退发起人靠它区分) */
110
+ submitType?: number;
111
+ /** code 7 · 被摘走的原参与人 */
112
+ fromActor?: string;
113
+ /** code 7 · 接手的新参与人 */
114
+ toActor?: string;
115
+ /** code 9 · 终止原因(无原因出空串,不省键) */
116
+ reason?: string;
36
117
  }
37
118
  export type ProcessEventListener = (event: ProcessEvent) => void | Promise<void>;
38
119
  export interface EngineExtensions {
@@ -1,11 +1,70 @@
1
+ /**
2
+ * 流程事件类型 —— **规范 11 §11.3「A 套整型码表」**(issues/132 整表重排 + issues/127 补 5/6/7/8/9)。
3
+ *
4
+ * ⚠️ 破坏性变更(spec §11.6 明写):本栈旧形状是 `iota` 起的 0..5 套
5
+ * (ProcessStart=0 / ProcessFinish=1 / ProcessReject=2 / TaskCreate=3 / TaskComplete=4 / CcCreate=5),
6
+ * 现整表重排到 A 套 1..9,与 Java/PHP/Rust/MoonBit/C# 同套:
7
+ * - CcCreate 5 → 4(4 号位由 Java 让出的死码 PROCESS_TASK_END 腾出,与 PHP v1.3.8 活码对齐)
8
+ * - TaskComplete 4 → 5
9
+ * - 旧 ProcessFinish(1) 与 ProcessReject(2) **合并**为 ProcessInstanceEnd(2)——办结/拒绝/撤回/终止
10
+ * 共用一支,靠载荷 `state` 分;"任务被退回"另立 TaskReject(6),不再混在实例终态里
11
+ * - TaskCreate → ProcessTaskStart(规范名)、ProcessStart → ProcessInstanceStart
12
+ *
13
+ * **规范名是权威,码值只是各栈内部的附带数值**(§11.3 首段):集成层跨语言判据一律按规范名分派,
14
+ * 不得拿数字码当判据(旧版已发布版本里数字码不可混用)。10+ 号段为超时催办/超时自动通过预留,
15
+ * 本轮不发(§11.4 第 1 条:八栈都无时钟扫描器,发了没有触发源)。
16
+ *
17
+ * 旧成员名(`ProcessStart`/`ProcessFinish`/`ProcessReject`/`TaskCreate`/`TaskComplete`/`CcCreate`)
18
+ * 按 §11.6「改名兼容义务」**保留一代**——别名在本 enum **外部**,见下方常量块(为什么不能写进来)。
19
+ */
1
20
  export var EventType;
2
21
  (function (EventType) {
3
- EventType[EventType["ProcessStart"] = 0] = "ProcessStart";
4
- EventType[EventType["ProcessFinish"] = 1] = "ProcessFinish";
5
- EventType[EventType["ProcessReject"] = 2] = "ProcessReject";
6
- EventType[EventType["TaskCreate"] = 3] = "TaskCreate";
7
- EventType[EventType["TaskComplete"] = 4] = "TaskComplete";
8
- // issues/102:抄送知会(对齐 Java CC_CREATE / Go EventCCCreate / Python CC_CREATE / PHP CC_CREATE;
9
- // 4 号位是活码 TaskComplete,0/1/2/3/4 不重排——码值契约 Go/Node=5)
10
- EventType[EventType["CcCreate"] = 5] = "CcCreate";
22
+ /** 1 · 实例发起成功——实例行 `insert` 之后 fire */
23
+ EventType[EventType["ProcessInstanceStart"] = 1] = "ProcessInstanceStart";
24
+ /** 2 · 实例进入终态——`state` 落库为 20/30/40/45/50/99 之后 fire,载荷带落库后的 `state` */
25
+ EventType[EventType["ProcessInstanceEnd"] = 2] = "ProcessInstanceEnd";
26
+ /** 3 · 新待办生成——每个任务行落库(分到 taskId)之后逐任务 fire,载荷带 `actors` */
27
+ EventType[EventType["ProcessTaskStart"] = 3] = "ProcessTaskStart";
28
+ /** 4 · 新增一条抄送记录——cc 行落库之后**逐抄送人** fire(发起 f_ccActors/办理 tf_ccActors/手动 createCCInstance 三条路径同判) */
29
+ EventType[EventType["CcCreate"] = 4] = "CcCreate";
30
+ /** 5 · 任务被办掉(同意/跳转/会签办理)——任务行 state 更新为已完成并落库之后;与 6 互斥 */
31
+ EventType[EventType["TaskComplete"] = 5] = "TaskComplete";
32
+ /** 6 · 任务被退回/拒绝(含退发起人、软拒绝、跳转回退)——退回动作使任务/实例落库之后;与 5 互斥 */
33
+ EventType[EventType["TaskReject"] = 6] = "TaskReject";
34
+ /** 7 · 转办发生——任务参与者被替换并落库之后 */
35
+ EventType[EventType["TaskTransfer"] = 7] = "TaskTransfer";
36
+ /** 8 · 撤回发生——撤回把实例 state 写 30 落库、被撤回任务行更新完成后 fire **一次**(不逐任务) */
37
+ EventType[EventType["TaskWithdraw"] = 8] = "TaskWithdraw";
38
+ /** 9 · 实例被终止——实例 state 写 40 落库之后(本栈当前无写 40 的门面动作,见 engine.notifyInstanceEnd) */
39
+ EventType[EventType["InstanceTerminated"] = 9] = "InstanceTerminated";
11
40
  })(EventType || (EventType = {}));
41
+ /**
42
+ * 旧成员名兼容别名 —— 规范 11 §11.6「改名兼容义务(八栈统一)」:成员改名时必须**保留旧成员名作为
43
+ * 同符号别名一代**并打 deprecate 注释,下一个代次再删。别名保的是"源码还能编过、switch 还能命中同一支",
44
+ * **不保数值**——本轮整表重排后旧码值已挪位,每条注释按「旧码 → 新码」标注(go 的
45
+ * `EventProcessStart = EventProcessInstanceStart` 即同形状;python 靠枚举成员别名做到"别名不参与
46
+ * list(EventType)",TS 数字枚举没有这个对应物,见下)。
47
+ *
48
+ * ⚠️ **TS 专有的坑(务必不要"顺手改优雅")**:这些别名必须写在 enum **外部**,绝不能写成 `enum`
49
+ * 的成员(`enum EventType { ProcessStart = 1, ProcessInstanceStart = 1, … }`)。数字枚举会为
50
+ * **每个**成员生成反向映射 `E[E["X"]=1]="X"`,同值的后声明成员会**覆盖** `E[1]` —— `EventType[1]`
51
+ * 就从 `'ProcessInstanceStart'` 变成 `'ProcessStart'`。集成层/L2-30 的事件流水 sink 靠 code→规范名
52
+ * 映射写 `<code>|<规范名>|<sourceId>`,反向映射被污染=线上假红。写成模块级常量则完全不进 `EventType`
53
+ * 对象:1..9 的反向映射与 `Object.keys(EventType)` 保持九支纯净(`__tests__/spec.test.ts` 的
54
+ * 「反向映射未被别名污染」格钉这条),别名只是同名同值的导出常量。
55
+ *
56
+ * 集成壳本轮一律**改用规范名**,不依赖别名续命(§11.6 末段)——别名只留给外部消费者一个代次的迁移窗口。
57
+ * §11.6 的"一代"窗口到期后,本块六条别名连同注释一并删除。
58
+ */
59
+ /** @deprecated 旧名(码 0)→ 规范名 `EventType.ProcessInstanceStart`(码 1):同一支,仅码值挪位。一代后删。 */
60
+ export const ProcessStart = EventType.ProcessInstanceStart;
61
+ /** @deprecated 旧名(码 1)→ 规范名 `EventType.ProcessInstanceEnd`(码 2):旧"办结"并入"实例终态",靠载荷 `state` 分。一代后删。 */
62
+ export const ProcessFinish = EventType.ProcessInstanceEnd;
63
+ /** @deprecated 旧名(码 2)→ 规范名 `EventType.ProcessInstanceEnd`(码 2):与 `ProcessFinish` **合并为同一支**(同码同物);"任务被退回"另立 `EventType.TaskReject`(6)。一代后删。 */
64
+ export const ProcessReject = EventType.ProcessInstanceEnd;
65
+ /** @deprecated 旧名(码 3)→ 规范名 `EventType.ProcessTaskStart`(码 3):名改码不改。一代后删。 */
66
+ export const TaskCreate = EventType.ProcessTaskStart;
67
+ /** @deprecated 旧名(码 4)→ 成员名沿用规范名 `EventType.TaskComplete`,但码值 4→5 挪位。此处导出的是"裸名"通道(`import { TaskComplete }`),一代后删。 */
68
+ export const TaskComplete = EventType.TaskComplete;
69
+ /** @deprecated 旧名(码 5)→ 成员名沿用规范名 `EventType.CcCreate`,但码值 5→4 挪位。同上,"裸名"通道,一代后删。 */
70
+ export const CcCreate = EventType.CcCreate;
package/dist/facade.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // action(boot2/boot3 端点短名)路由。返回统一结构 {code, msg, data}
5
5
  // (code=0 成功 / 99999999 失败)。操作人约定:args.operator 显式传入。
6
6
  import { TaskState, } from './model.js';
7
- import { KeyAutoExecute, KeyAdminID, KeyNextNodeOperator, KeyProcessStartNextNodeOperator, isCountersign } from './engine.js';
7
+ import { KeyAutoExecute, KeyAdminID, KeyCcActorsStart, KeyNextNodeOperator, KeyProcessStartNextNodeOperator, isCountersign } from './engine.js';
8
8
  import { EventType } from './extensions.js';
9
9
  // submitType 枚举(对齐 boot3)
10
10
  const SUBMIT_APPLY = 0;
@@ -163,18 +163,10 @@ export class JeeflowFacade {
163
163
  flowArgs[k] = v;
164
164
  }
165
165
  const inst = await this.engine.startProcessInstanceById(defineId, operator, flowArgs);
166
- // issues/56 E28:发起时抄送(f_ccActors)创建 cc 实例(对齐 Java enableCcActors 语义)
167
- const ccList = Array.isArray(flowArgs.f_ccActors) ? flowArgs.f_ccActors
168
- : typeof flowArgs.f_ccActors === 'string' && flowArgs.f_ccActors.trim()
169
- ? flowArgs.f_ccActors.split(',').map((x) => x.trim()).filter(Boolean) : [];
170
- if (ccList.length > 0) {
171
- await this.repo.createCcInstance(inst.id, operator, ...ccList);
172
- // issues/102:CC 实例落库后逐抄送人 fire CcCreate(ccActorId 直传事件体,
173
- // 对齐 Go startAndExecute / Python _startAndExecute;监听器据此落抄送知会 NOTICE)
174
- for (const actor of ccList) {
175
- await this.engine.fireEvent({ type: EventType.CcCreate, instanceId: inst.id, operator, ccActorId: actor });
176
- }
177
- }
166
+ // issues/56 E28 + issues/127:发起时抄送(f_ccActors)——cc 行落库后逐人 fire CC_CREATE(4)。
167
+ // 与办理腿 tf_ccActors、手动腿 createCCInstance 共用引擎那一个漏斗(Java handleCcActors 同形),
168
+ // 三条路径同一码,不在门面各写一份 fire 循环。
169
+ await this.engine.handleCcActors(inst.id, operator, flowArgs[KeyCcActorsStart]);
178
170
  // startAndExecute:自动完成申请节点(assignee="applicant" → 发起人)
179
171
  const doing = await this.repo.findDoingTasks(inst.id);
180
172
  for (const task of doing) {
@@ -281,6 +273,11 @@ export class JeeflowFacade {
281
273
  const isActor = withdrawn.some(t => (t.actorIds ?? []).includes(operator));
282
274
  if (!isSystem && !isStarter && !isActor)
283
275
  throw new Error('无权限撤回该流程实例');
276
+ // issues/53 E25:撤回状态应为 Withdraw(30) 而非 Reject(45)(对齐 Java)
277
+ // issues/134 案 A:实例状态守卫在聚合根 withdraw 内(state≠10 ⇒ 抛 20010009 固定文案),
278
+ // 故排在任务行改写**之前**——被拒时任务行与实例一行都不动,下方两次落库也走不到。
279
+ inst.withdraw(now);
280
+ inst.updateUser = operator;
284
281
  for (const t of withdrawn) {
285
282
  // issues/113:撤回写 Withdraw(30),不用 Abandoned(99)——99 是引擎废弃码
286
283
  // (会签一票否决 / abandonAllDoing 用它),混用会让撤回单与废弃单在任务表里塌成同值
@@ -288,9 +285,6 @@ export class JeeflowFacade {
288
285
  // issues/114:进行中任务的 update_user 同样回写为撤回人(与实例口径一致)
289
286
  t.updateUser = operator;
290
287
  }
291
- // issues/53 E25:撤回状态应为 Withdraw(30) 而非 Reject(45)(对齐 Java)
292
- inst.withdraw(now);
293
- inst.updateUser = operator;
294
288
  // 级联覆盖防护(issues/57 补正):撤回副本同步回聚合——updateInstance 级联会用
295
289
  // 聚合内旧任务覆盖已撤回状态(memory 加载 tasks 时必现);已完成(20)/已终止(40)
296
290
  // 任务行不在 withdrawn 内,天然不被改写
@@ -298,6 +292,14 @@ export class JeeflowFacade {
298
292
  for (const t of withdrawn)
299
293
  await this.repo.updateTask(t);
300
294
  await this.repo.updateInstance(inst);
295
+ // §11.3 code 8:撤回把实例 state 写 30 落库、被撤回任务行也更新完成后 fire **一次**
296
+ // (每轮撤回只 fire 一次,不逐任务——规范 08 场景 34)。
297
+ // **撤回只发 8,不补发 2**——规范 11 §11.3 码 2 的语义是「流程自己走到终点」(办结 20/
298
+ // 拒绝到终态 45),撤回(30)不是走到终点;同轮既发 8 又发 2 会让下游监听器给发起人推一条
299
+ // 「流程已办结」的错通知(规范 08 场景 32/34 明写「撤回(30)/终止(40) 不发 2」,node 首版即此形状,已纠)。
300
+ // notifyInstanceEnd 漏斗保留给办结/拒绝路径(engine.executeAndJumpToEnd、结束节点落库),
301
+ // withdraw 不再进这个漏斗。
302
+ await this.engine.fireEvent({ type: EventType.TaskWithdraw, instanceId, operator });
301
303
  }
302
304
  // ── 流程任务 ─────────────────────────────────────────────────────────────
303
305
  async execute(args) {
@@ -859,11 +861,9 @@ export class JeeflowFacade {
859
861
  const actors = toStringList2(args.actorIds);
860
862
  if (actors.length === 0)
861
863
  throw new Error('actorIds 缺失');
862
- await this.repo.createCcInstance(instanceId, operator, ...actors);
863
- // issues/102:手动 CC 与发起路径同语义——逐抄送人 fire CcCreate
864
- for (const actor of actors) {
865
- await this.engine.fireEvent({ type: EventType.CcCreate, instanceId, operator, ccActorId: actor });
866
- }
864
+ // issues/102 + issues/127/132:手动 CC 与发起/办理两条腿同码同漏斗——§11.2 原则 1
865
+ // "码值表达发生了什么事实,不表达谁触发的",故手动路径照样 fire CC_CREATE(4)。
866
+ await this.engine.handleCcActors(instanceId, operator, actors);
867
867
  }
868
868
  async updateCCStatus(args) {
869
869
  const instanceId = toId(args.processInstanceId);
@@ -1095,6 +1095,12 @@ export class JeeflowFacade {
1095
1095
  // 仓储 updateTask 会以任务副本的 actorIds 覆写参与者(memory 语义),须同步为摘/加后的最新值
1096
1096
  task.actorIds = await this.repo.findTaskActors(taskId);
1097
1097
  await this.repo.updateTask(task);
1098
+ // §11.3 code 7:参与者被替换并落库**之后** fire(场景 34:载荷带 fromActor/toActor/operator)。
1099
+ // 转办不碰实例 state,故不发 2;也不发 5/6(任务没被办掉,只是换了人)。
1100
+ await this.engine.fireEvent({
1101
+ type: EventType.TaskTransfer, instanceId: task.processInstanceId, taskId,
1102
+ operator, fromActor, toActor,
1103
+ });
1098
1104
  }
1099
1105
  async taskLatest(args) {
1100
1106
  const instanceId = toId(args.processInstanceId);
package/dist/index.d.ts CHANGED
@@ -8,5 +8,6 @@ export type { ProcessRepository, ProcessExtRepository, UserProvider, OrgUserProv
8
8
  export { SqliteDynamicTableWriter, PersistPostInterceptor, registerPersistMeta, type DynamicTableWriter, type DefineLoader, } from './persist.js';
9
9
  export { registerBuiltinAssignments, OperatorAssignmentHandler, FormFieldAssigneeHandler, DeptLeaderAssignmentHandler, DeptMainLeaderAssignmentHandler, ApplicantDeptLeaderAssignmentHandler, ApplicantDeptMainLeaderAssignmentHandler, TaskRoleAssigneeHandler, HANDLER_OPERATOR_ASSIGNMENT, HANDLER_FORM_FIELD_ASSIGNEE, HANDLER_DEPT_LEADER, HANDLER_DEPT_MAIN_LEADER, HANDLER_APPLICANT_DEPT_LEADER, HANDLER_APPLICANT_DEPT_MAIN_LEADER, HANDLER_TASK_ROLE_ASSIGNEE, } from './builtin.js';
10
10
  export { JeeflowFacade } from './facade.js';
11
+ export { EventType, ProcessStart, ProcessFinish, ProcessReject, TaskCreate, TaskComplete, CcCreate, } from './extensions.js';
11
12
  export type { EngineExtensions, FlowInterceptor, ProcessEventListener, ProcessEvent, AssignmentHandler, DecisionHandler } from './extensions.js';
12
13
  export { JdbcProcessExtRepository } from './jdbc/ext.js';
package/dist/index.js CHANGED
@@ -8,4 +8,11 @@ export { SqliteDynamicTableWriter, PersistPostInterceptor, registerPersistMeta,
8
8
  export { registerBuiltinAssignments, OperatorAssignmentHandler, FormFieldAssigneeHandler, DeptLeaderAssignmentHandler, DeptMainLeaderAssignmentHandler, ApplicantDeptLeaderAssignmentHandler, ApplicantDeptMainLeaderAssignmentHandler, TaskRoleAssigneeHandler, HANDLER_OPERATOR_ASSIGNMENT, HANDLER_FORM_FIELD_ASSIGNEE, HANDLER_DEPT_LEADER, HANDLER_DEPT_MAIN_LEADER, HANDLER_APPLICANT_DEPT_LEADER, HANDLER_APPLICANT_DEPT_MAIN_LEADER, HANDLER_TASK_ROLE_ASSIGNEE, } from './builtin.js';
9
9
  // issues/35:包导出面补齐——门面/扩展类型/扩展仓储(集成方组装完整引擎链)
10
10
  export { JeeflowFacade } from './facade.js';
11
+ // issues/132 §11.3:码表重排后 EventType 必须能从包门面 value-import——
12
+ // `./extensions` 子路径不在 exports map 里(集成层此前只能在自己仓镜像一份数字码,
13
+ // nestjs 壳 wf-message.listener.spec.ts 就是这么写的),拿规范名分派的契约要求
14
+ // 得有一个公开入口,否则下一栈又会发明第四套码值。
15
+ // §11.6 改名兼容义务:六个旧成员名的别名走**同一条出口**(外部第三方 import 面只有本门面),
16
+ // 别名是 enum 外部的同值常量(详见 extensions.ts 的反向映射坑注释),一代后随源码一并删除。
17
+ export { EventType, ProcessStart, ProcessFinish, ProcessReject, TaskCreate, TaskComplete, CcCreate, } from './extensions.js';
11
18
  export { JdbcProcessExtRepository } from './jdbc/ext.js';
@@ -30,7 +30,11 @@ export declare class JdbcProcessExtRepository implements ProcessExtRepository {
30
30
  * a. 作用域:先在该流程名作用域内取记录,该作用域**一条都没有**才兜底
31
31
  * `process_name IS NULL OR = ''`(全流程委托);精确作用域里只要有记录就由它裁决;
32
32
  * 然后由 `surrogateIsEffective` 裁决**这一条**:
33
- * d. enabled 严格 1('1'/1 同结论,NULL 不生效)、c. 自委托过滤、
33
+ * d. enabled **只认数值 1**('1'/'1.0'/true/null 一律停用,issues/130 案 A;不与 SQL 侧
34
+ * `enabled = 1` 的隐式转换"等价"——那是驱动/连接层改写列值的包袱,非运行期口径)。
35
+ * INT 列被驱动回读成字符串(`'1'`)由**本仓储的读侧边界**在交判据前还原成数值
36
+ * ({@link queryNewestSurrogate} 调 `surrogateHydrateEnabled`),判据本身不吃串;
37
+ * c. 自委托过滤、
34
38
  * b. 时间窗 start<=at<=end(任一侧 NULL = 该侧不限;`at` 传 null 则整段跳过窗比较)。
35
39
  *
36
40
  * ⚠️ 旧形状是 `WHERE operator=? AND enabled=1 AND surrogate<>? AND 窗口… ORDER BY id DESC LIMIT 1`
package/dist/jdbc/ext.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
5
5
  import { isBlankOwnership, isBlankValue } from '../spi.js';
6
6
  import { TsIDGenerator, rowId } from './shared.js';
7
- import { surrogateIsEffective, surrogateTimeMs } from '../surrogate-rule.js';
7
+ import { surrogateIsEffective, surrogateTimeMs, surrogateHydrateEnabled } from '../surrogate-rule.js';
8
8
  const txStore = new AsyncLocalStorage();
9
9
  export class JdbcProcessExtRepository {
10
10
  adapter;
@@ -285,7 +285,11 @@ export class JdbcProcessExtRepository {
285
285
  * a. 作用域:先在该流程名作用域内取记录,该作用域**一条都没有**才兜底
286
286
  * `process_name IS NULL OR = ''`(全流程委托);精确作用域里只要有记录就由它裁决;
287
287
  * 然后由 `surrogateIsEffective` 裁决**这一条**:
288
- * d. enabled 严格 1('1'/1 同结论,NULL 不生效)、c. 自委托过滤、
288
+ * d. enabled **只认数值 1**('1'/'1.0'/true/null 一律停用,issues/130 案 A;不与 SQL 侧
289
+ * `enabled = 1` 的隐式转换"等价"——那是驱动/连接层改写列值的包袱,非运行期口径)。
290
+ * INT 列被驱动回读成字符串(`'1'`)由**本仓储的读侧边界**在交判据前还原成数值
291
+ * ({@link queryNewestSurrogate} 调 `surrogateHydrateEnabled`),判据本身不吃串;
292
+ * c. 自委托过滤、
289
293
  * b. 时间窗 start<=at<=end(任一侧 NULL = 该侧不限;`at` 传 null 则整段跳过窗比较)。
290
294
  *
291
295
  * ⚠️ 旧形状是 `WHERE operator=? AND enabled=1 AND surrogate<>? AND 窗口… ORDER BY id DESC LIMIT 1`
@@ -321,7 +325,17 @@ export class JdbcProcessExtRepository {
321
325
  const conn = await this.c();
322
326
  try {
323
327
  const rows = await conn.fetchAll(this.sql(sql), args);
324
- return rows.length > 0 ? this.mapSurrogate(rows[0]) : null;
328
+ if (rows.length === 0)
329
+ return null;
330
+ const newest = this.mapSurrogate(rows[0]);
331
+ // issues/130 案 A 的**驱动边界**还原:`enabled` 是 INT 列(tests/schema/schema-mysql.sql),
332
+ // 而驱动不保证回读成数值——mysql2 关掉 typeCast、pg 的 int8/numeric、文本协议驱动一律给字符串
333
+ // '1'。判据 d 只认数值 1 之后不在这里还原,就会让这类宿主的委托**整体判废且零告警**
334
+ // (Java rs.getInt / Go Scan(&int) / C# GetFieldValue<int> / PHP hydrateEnabled 干的是同一件事)。
335
+ // ⚠️ 只规范整数串被还原('1.0' / 'abc' / ' 1' 原样交判据 ⇒ 停用),不是把宽接受集合放回去;
336
+ // 也**不动** findSurrogateById / pageSurrogates 的台账回显(那里要看到的是列原值)。
337
+ newest.enabled = surrogateHydrateEnabled(newest.enabled);
338
+ return newest;
325
339
  }
326
340
  finally {
327
341
  await this.done(conn);
@@ -14,6 +14,9 @@ export declare class MemoryExtRepository implements ProcessExtRepository {
14
14
  listDesignHis(designId: string): Promise<ProcessDesignHis[]>;
15
15
  findSurrogateById(id: string): Promise<ProcessSurrogate | null>;
16
16
  saveSurrogate(s: ProcessSurrogate): Promise<void>;
17
+ /** 整行覆盖,**不做**写侧归一(与 saveSurrogate 有意不对称,对齐 PHP InMemoryProcessExtRepository::updateSurrogate):
18
+ * 这里是"台账里就是调用方给的原始值"的唯一显形路径=业务方自定义 SPI 仓储回行传非整数 enabled
19
+ * (issues/130 §2 的分叉源,案 A 由实现侧自己归一 ⇒ 本栈严判据判停用)。issues/130 脏值矩阵走这一路。 */
17
20
  updateSurrogate(s: ProcessSurrogate): Promise<void>;
18
21
  removeSurrogate(id: string): Promise<void>;
19
22
  pageSurrogates(_pageNum?: number, _pageSize?: number, filters?: Record<string, any>, conditions?: QueryCondition[]): Promise<[ProcessSurrogate[], number]>;
@@ -24,7 +27,8 @@ export declare class MemoryExtRepository implements ProcessExtRepository {
24
27
  * 精确作用域里只要有记录就由它裁决,**不跨作用域回落**;
25
28
  * b. 时间窗 start_time <= at <= end_time,任一侧为空 = 该侧不限;`at` 解析不出时刻则整段跳过窗比较
26
29
  * (保留 `at: Date = new Date()` 显式传 null 的老语义);
27
- * c. 自委托过滤 surrogate <> operator;d. enabled 只认整数 1。
30
+ * c. 自委托过滤 surrogate <> operator;d. enabled 只认**数值** 1(`'1'`/`true` 一律停用;
31
+ * 直写台账的规范整数串由 {@link saveSurrogate} 的写侧边界先归一,判据本身不吃串)。
28
32
  *
29
33
  * ⚠️ 顺序是「**先**按主键 id 取最新一条 → **再**由四判据裁决这一条」(条款 1.4 + issues/123):
30
34
  * 反过来(先滤生效、剩下的才取最新)等于"历史上留过一条窗内委托就永久生效",
@@ -1,6 +1,6 @@
1
1
  // 扩展仓储内存实现(v1.1.0,测试/演示用)
2
2
  import { matchConditions } from './memory.js';
3
- import { surrogateIsEffective, surrogateTimeMs, newestOf } from './surrogate-rule.js';
3
+ import { surrogateIsEffective, surrogateTimeMs, surrogateHydrateEnabled, newestOf } from './surrogate-rule.js';
4
4
  // ═══ 条件匹配基建(issues/05-5) ═══
5
5
  const DESIGN_FIELDS = {
6
6
  't.id': 'id', 't.name': 'name', 't.display_name': 'displayName', 't.type': 'type',
@@ -74,8 +74,17 @@ export class MemoryExtRepository {
74
74
  if (!s.updateTime)
75
75
  s.updateTime = now;
76
76
  // 显式 enabled=0 是合法值(停用委托);缺省由门面处理(对齐 Java/Go/Python,issues/82-7)
77
+ // issues/130 案 A 的**写侧台账边界**:本表 enabled 建模的是 INT 列(tests/schema/*.sql),
78
+ // 把 `'1'` 直写进 INT 列,落进去的就是数值 1——SQL 仓由数据库做这一步,内存仓没人做,
79
+ // 于是绕过门面的仓储直写会把文本 `'1'` 原样留在台账里,读侧严判据(只认数值 1)必然判废。
80
+ // ⚠️ 只还原**规范整数串**(`surrogateHydrateEnabled`),`'abc'` / `'1.0'` / `true` 原样留着
81
+ // 交判据停用(用例 27 p3~p6 钉的就是这一半);这不是把接受集合放宽回去,也不动门面写侧归一。
82
+ s.enabled = surrogateHydrateEnabled(s.enabled);
77
83
  this.surrogates.set(s.id, { ...s });
78
84
  }
85
+ /** 整行覆盖,**不做**写侧归一(与 saveSurrogate 有意不对称,对齐 PHP InMemoryProcessExtRepository::updateSurrogate):
86
+ * 这里是"台账里就是调用方给的原始值"的唯一显形路径=业务方自定义 SPI 仓储回行传非整数 enabled
87
+ * (issues/130 §2 的分叉源,案 A 由实现侧自己归一 ⇒ 本栈严判据判停用)。issues/130 脏值矩阵走这一路。 */
79
88
  async updateSurrogate(s) {
80
89
  s.updateTime = new Date();
81
90
  this.surrogates.set(s.id, { ...s });
@@ -111,7 +120,8 @@ export class MemoryExtRepository {
111
120
  * 精确作用域里只要有记录就由它裁决,**不跨作用域回落**;
112
121
  * b. 时间窗 start_time <= at <= end_time,任一侧为空 = 该侧不限;`at` 解析不出时刻则整段跳过窗比较
113
122
  * (保留 `at: Date = new Date()` 显式传 null 的老语义);
114
- * c. 自委托过滤 surrogate <> operator;d. enabled 只认整数 1。
123
+ * c. 自委托过滤 surrogate <> operator;d. enabled 只认**数值** 1(`'1'`/`true` 一律停用;
124
+ * 直写台账的规范整数串由 {@link saveSurrogate} 的写侧边界先归一,判据本身不吃串)。
115
125
  *
116
126
  * ⚠️ 顺序是「**先**按主键 id 取最新一条 → **再**由四判据裁决这一条」(条款 1.4 + issues/123):
117
127
  * 反过来(先滤生效、剩下的才取最新)等于"历史上留过一条窗内委托就永久生效",
package/dist/model.d.ts CHANGED
@@ -157,7 +157,16 @@ export declare class ProcessInstance {
157
157
  finish(now: Date): void;
158
158
  /** 驳回流程 */
159
159
  reject(now: Date): void;
160
- /** 撤回流程(issues/53 E25:withdraw 用 Withdraw(30),与 reject 区分) */
160
+ /** 撤回流程(issues/53 E25:withdraw 用 Withdraw(30),与 reject 区分)
161
+ *
162
+ * issues/134 案 A(owner 2026-09-28 拍板 A):撤回作用于**实例**时,实例状态不是
163
+ * 10(进行中) 一律拒——守卫排在改写之前,被拒时实例 state 不被改写、不落库
164
+ * (改前对已办结(20)/已终止(40)的实例调撤回会静默改写成 30,已办列表与按状态
165
+ * 聚合的统计口径凭空改历史且用户看不到任何报错)。
166
+ * 内部码 20010009(八栈同码;本栈既有形状 20010007/20010008 同样是"码进注释、
167
+ * msg 只出固定中文文案",见 engine.ts rollbackToParent)。出口按 issues/121 口径:
168
+ * 门面吞内部码 ⇒ code=99999999 + msg 逐字 `流程实例非进行中,无法撤回`,不拼码。
169
+ * 任务行层面既有保护(20/40 任务行不得被撤回改写)保持原样,实例级守卫排在它之前。 */
161
170
  withdraw(now: Date): void;
162
171
  /** 追加变量 */
163
172
  addVariable(vars: Record<string, any>): void;
package/dist/model.js CHANGED
@@ -130,8 +130,20 @@ export class ProcessInstance {
130
130
  this.state = InstanceState.Reject;
131
131
  this.updateTime = now;
132
132
  }
133
- /** 撤回流程(issues/53 E25:withdraw 用 Withdraw(30),与 reject 区分) */
133
+ /** 撤回流程(issues/53 E25:withdraw 用 Withdraw(30),与 reject 区分)
134
+ *
135
+ * issues/134 案 A(owner 2026-09-28 拍板 A):撤回作用于**实例**时,实例状态不是
136
+ * 10(进行中) 一律拒——守卫排在改写之前,被拒时实例 state 不被改写、不落库
137
+ * (改前对已办结(20)/已终止(40)的实例调撤回会静默改写成 30,已办列表与按状态
138
+ * 聚合的统计口径凭空改历史且用户看不到任何报错)。
139
+ * 内部码 20010009(八栈同码;本栈既有形状 20010007/20010008 同样是"码进注释、
140
+ * msg 只出固定中文文案",见 engine.ts rollbackToParent)。出口按 issues/121 口径:
141
+ * 门面吞内部码 ⇒ code=99999999 + msg 逐字 `流程实例非进行中,无法撤回`,不拼码。
142
+ * 任务行层面既有保护(20/40 任务行不得被撤回改写)保持原样,实例级守卫排在它之前。 */
134
143
  withdraw(now) {
144
+ const NOT_DOING = '流程实例非进行中,无法撤回'; // 内部码 20010009
145
+ if (this.state !== InstanceState.Doing)
146
+ throw new Error(NOT_DOING);
135
147
  this.state = InstanceState.Withdraw;
136
148
  this.updateTime = now;
137
149
  }
@@ -1,8 +1,38 @@
1
1
  import type { ProcessSurrogate } from './model.js';
2
2
  /** 时间归一为毫秒:Date/毫秒数/可解析字符串均可;空值或脏值 → null(该侧不限,对齐 SQL 侧 NULL) */
3
3
  export declare function surrogateTimeMs(v: any): number | null;
4
- /** enabled 只认整数 1('1' 视作 1,与 SQL 侧 INT 列同结论);脏值('abc'/true/0/2/空)一律不启用 */
4
+ /**
5
+ * enabled **只认整数 1**(issues/130 案 A):与 Java `Integer.valueOf(1).equals(enabled)`、
6
+ * Go `Enabled int != 1` 同阵营——字符串 `'1'`/`'1.0'`、布尔 `true`、`null`/`undefined` 及
7
+ * 0/2 等其它整数一律停用,不接受任何"看起来像 1"的等价写法。
8
+ *
9
+ * ⚠️ 这不是"与 SQL 侧 `enabled = 1` 隐式转换等价":SQL 的宽松数值比较(MySQL 甚至 `'abc'=0`)
10
+ * 是**驱动/连接层**改写列值的历史包袱,不是运行期裁决该追随的口径(见 issues/130 附加义务:
11
+ * 驱动/连接层不得改写 enabled 原值)。
12
+ *
13
+ * ⚠️ 判据本身**不吃串**,所以"整数列在边界上变成字符串"必须由**边界**还原({@link surrogateHydrateEnabled}),
14
+ * 三个内置边界各管一段,都不动本判据:
15
+ * - SQL 仓读侧(`JdbcProcessExtRepository.queryNewestSurrogate`):驱动把 INT 列回读成 `'1'`;
16
+ * - 内存仓写侧(`MemoryExtRepository.saveSurrogate`):台账建模的是 INT 列,调用方直传
17
+ * 规范整数串时按列语义落数值(门面 `processSurrogate/*` 的写侧归一只覆盖 API 入口,
18
+ * 绕过门面的仓储直写属这一段);
19
+ * - 业务方自定义 SPI 仓储传非整数 enabled 属 issues/130 §2 的分叉源,由实现侧自己归一。
20
+ */
5
21
  export declare function surrogateEnabled(v: any): boolean;
22
+ /**
23
+ * **边界还原**:把整数列被驱动字符串化 / 调用方按文本传进来的**规范整数串**换回数值,
24
+ * 再交 {@link surrogateEnabled} 裁决(姿势对齐 PHP `SurrogateRule::hydrateEnabled`、
25
+ * Java `rs.getInt`、Go `Scan(&int)`、C# `GetFieldValue<int>`)。
26
+ *
27
+ * 为什么需要:`wf_process_surrogate.enabled` 是 `INT` 列(tests/schema/schema-mysql.sql),
28
+ * 但驱动不保证给回数值——mysql2 关掉 typeCast、pg 的 int8/numeric、以及任何"文本协议"驱动都会
29
+ * 给字符串 `'1'`。判据只认数值 1 之后不在边界还原,就会让这类宿主的委托**整体判废且零告警**。
30
+ *
31
+ * ⚠️ 这**不是**把接受集合放宽回去:只认规范整数串 `-?(0|[1-9]\d*)`(无空格、无前导零、无小数点、
32
+ * 无加号),`'1.0'` / `' 1'` / `'01'` / `'+1'` / `'1abc'` / `'abc'` / `''` 以及 `true` / `null`
33
+ * 一律**原样返回**,交判据判停用。非字符串入参(数值/布尔/null)同样原样透传。
34
+ */
35
+ export declare function surrogateHydrateEnabled(v: any): any;
6
36
  /**
7
37
  * 判据 1.4:比较两条委托的主键大小(a 是否比 b 旧)。id 是雪花数字串(19 位,已超
8
38
  * Number 安全整数),纯数字串一律按 BigInt 比**数值**(与 SQL 侧 `ORDER BY id DESC` 同序),
@@ -29,15 +29,45 @@ export function surrogateTimeMs(v) {
29
29
  }
30
30
  return null;
31
31
  }
32
- /** enabled 只认整数 1('1' 视作 1,与 SQL 侧 INT 列同结论);脏值('abc'/true/0/2/空)一律不启用 */
32
+ /**
33
+ * enabled **只认整数 1**(issues/130 案 A):与 Java `Integer.valueOf(1).equals(enabled)`、
34
+ * Go `Enabled int != 1` 同阵营——字符串 `'1'`/`'1.0'`、布尔 `true`、`null`/`undefined` 及
35
+ * 0/2 等其它整数一律停用,不接受任何"看起来像 1"的等价写法。
36
+ *
37
+ * ⚠️ 这不是"与 SQL 侧 `enabled = 1` 隐式转换等价":SQL 的宽松数值比较(MySQL 甚至 `'abc'=0`)
38
+ * 是**驱动/连接层**改写列值的历史包袱,不是运行期裁决该追随的口径(见 issues/130 附加义务:
39
+ * 驱动/连接层不得改写 enabled 原值)。
40
+ *
41
+ * ⚠️ 判据本身**不吃串**,所以"整数列在边界上变成字符串"必须由**边界**还原({@link surrogateHydrateEnabled}),
42
+ * 三个内置边界各管一段,都不动本判据:
43
+ * - SQL 仓读侧(`JdbcProcessExtRepository.queryNewestSurrogate`):驱动把 INT 列回读成 `'1'`;
44
+ * - 内存仓写侧(`MemoryExtRepository.saveSurrogate`):台账建模的是 INT 列,调用方直传
45
+ * 规范整数串时按列语义落数值(门面 `processSurrogate/*` 的写侧归一只覆盖 API 入口,
46
+ * 绕过门面的仓储直写属这一段);
47
+ * - 业务方自定义 SPI 仓储传非整数 enabled 属 issues/130 §2 的分叉源,由实现侧自己归一。
48
+ */
33
49
  export function surrogateEnabled(v) {
34
- if (typeof v === 'number')
35
- return v === 1;
36
- if (typeof v === 'string') {
37
- const s = v.trim();
38
- return s !== '' && Number.isInteger(Number(s)) && Number(s) === 1;
39
- }
40
- return false;
50
+ // typeof 先过:'1'/'1.0'/true/null 皆非 number 直接停;Number.isInteger + === 1 双闸,
51
+ // 排除 2/0/NaN/小数——只有整数 1 通过。
52
+ return typeof v === 'number' && Number.isInteger(v) && v === 1;
53
+ }
54
+ /**
55
+ * **边界还原**:把整数列被驱动字符串化 / 调用方按文本传进来的**规范整数串**换回数值,
56
+ * 再交 {@link surrogateEnabled} 裁决(姿势对齐 PHP `SurrogateRule::hydrateEnabled`、
57
+ * Java `rs.getInt`、Go `Scan(&int)`、C# `GetFieldValue<int>`)。
58
+ *
59
+ * 为什么需要:`wf_process_surrogate.enabled` 是 `INT` 列(tests/schema/schema-mysql.sql),
60
+ * 但驱动不保证给回数值——mysql2 关掉 typeCast、pg 的 int8/numeric、以及任何"文本协议"驱动都会
61
+ * 给字符串 `'1'`。判据只认数值 1 之后不在边界还原,就会让这类宿主的委托**整体判废且零告警**。
62
+ *
63
+ * ⚠️ 这**不是**把接受集合放宽回去:只认规范整数串 `-?(0|[1-9]\d*)`(无空格、无前导零、无小数点、
64
+ * 无加号),`'1.0'` / `' 1'` / `'01'` / `'+1'` / `'1abc'` / `'abc'` / `''` 以及 `true` / `null`
65
+ * 一律**原样返回**,交判据判停用。非字符串入参(数值/布尔/null)同样原样透传。
66
+ */
67
+ export function surrogateHydrateEnabled(v) {
68
+ if (typeof v === 'string' && /^-?(0|[1-9]\d*)$/.test(v))
69
+ return Number(v);
70
+ return v;
41
71
  }
42
72
  /**
43
73
  * 判据 1.4:比较两条委托的主键大小(a 是否比 b 旧)。id 是雪花数字串(19 位,已超
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mldong/jeeflow",
3
- "version": "1.8.33",
3
+ "version": "1.8.35",
4
4
  "description": "jeeflow workflow engine — Node.js / TypeScript implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",