@mldong/jeeflow 1.8.32 → 1.8.34

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
@@ -125,3 +125,18 @@ export declare function mergeAgents(actors: string[], agents: Map<string, string
125
125
  * '1' / 'ALL' / 'COUNTERSIGN'(大小写不敏感)→ 会签。
126
126
  * 设计器属性面板保存 'ALL' 字符串符合 Java 契约,引擎必须兼容 */
127
127
  export declare function isCountersign(v: any): boolean;
128
+ /**
129
+ * 解析期待完成时间(逐字移植 Java `FlowUtil.processTime` / C# `FlowUtil.ProcessTime`,本栈原先没有)。
130
+ *
131
+ * 三档语义,**顺序不能变**:
132
+ * 1. `args` 里存在键名等于 expr 原串的项 ⇒ 取该项的值:Date / 毫秒时间戳 / `"yyyy-MM-dd HH:mm:ss"`
133
+ * → 该时刻;字符串解析失败 → **null**(不是 now);其它类型(布尔/数组/对象/小数)→ **落穿**到下面两档
134
+ * (Java/C# 都是落穿,不许当"解析失败"提前 return null)。
135
+ * 2. 否则 expr 以 `s`/`m`/`h`/`d` 结尾且前缀是整数 ⇒ now + N 秒/分/时/天(`d` 走**日历加天**,不乘 86400 秒)。
136
+ * 3. 否则把 expr 本身按 `"yyyy-MM-dd HH:mm:ss"` 解析 → 时刻;失败 → null。
137
+ *
138
+ * ⚠️ 任何一档都不得退回 now()——"算不出来就写当前时间"正是 issues/126 的病灶(建单即逾期,逾期统计恒失真)。
139
+ *
140
+ * @param now 取时基准=**本栈写 createTime 用的同一个 Date**(本栈无时钟槽,与 Java 直接用系统钟同档)
141
+ */
142
+ export declare function processTime(expr: string, args: Record<string, any> | undefined, now: Date): Date | null;
package/dist/engine.js CHANGED
@@ -272,6 +272,12 @@ export class EngineImpl {
272
272
  const eff = mergeAgents([actors[lc + 1]], await this.surrogateAgents([actors[lc + 1]], pn));
273
273
  if (eff.length > 1)
274
274
  nt.actorIds = eff;
275
+ // issues/126 案 A · **第五处写点**:这一支绕过 createTask helper 直建任务行,所以必须显式补一次
276
+ // ——基准侧 boot2 的串行推进是回调 createCountersignTask(ProcessTaskServiceImpl:485,
277
+ // 内含 :524 那处到期写)⇒ 基准形状里"推进出的第二/第三位成员"同样带到期时间;
278
+ // 不补就是"首成员有到期、后续没有"(对齐 Java CountersignHandler.applyNodeExpireTime @ cb541d4)。
279
+ // 变量源=实例变量(与建单同档),取时基准=本行 createTime 用的同一个 now。
280
+ applyNodeExpireTime(nt, curNode.properties?.expireTime, inst.variables, now);
275
281
  await this.repo.saveTask(nt);
276
282
  // TASK_CREATE:顺序会签推进新任务落库后 fire(对齐 Java CreateTaskHandler / Rust)
277
283
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: curNode.id, operator });
@@ -415,9 +421,15 @@ export class EngineImpl {
415
421
  let actor = isFirst ? String(his.variables?.u_userId ?? '') || inst.operator : his.actorId;
416
422
  if (!actor)
417
423
  throw new Error(NO_LINEAGE);
418
- const nt = inst.createTask(this.nextId(), prev.id, prev.text.value, actor, his.createUser ?? '', prev.properties?.form ?? '', new Date(), his.parentTaskId ?? '0', isFirst, his.performType);
424
+ // 取时基准只取一次:本行 createTime 与 expire_time 共用同一个 Date(写点内不另起时钟)
425
+ const now = new Date();
426
+ const nt = inst.createTask(this.nextId(), prev.id, prev.text.value, actor, his.createUser ?? '', prev.properties?.form ?? '', now, his.parentTaskId ?? '0', isFirst, his.performType);
419
427
  // 复活行只带数据类键:tf_*(上次表单提交)与 csv_*/会签簿记都是"上次提交"的残留
420
428
  nt.variables = { ...lineageVars(his.variables), isFirstTaskNode: isFirst };
429
+ // issues/126 案 A · 回退新建写点:表达式取**被回退掉的那个节点**(=当前节点)的 expireTime,
430
+ // 变量源用随行拷贝那份(boot2 的 hisVariable)——两点都与 Java rejectTask 逐字一致。
431
+ // 取时基准 now 同时是本行 createTime 的值,勿另起时钟(否则同行 create→expire 差值带偏差)。
432
+ applyNodeExpireTime(nt, findNode(flow, task.taskName)?.properties?.expireTime, nt.variables, now);
421
433
  const agents = await this.surrogateAgents([actor], await this.surrogateProcessName(flow, inst));
422
434
  const eff = mergeAgents([actor], agents);
423
435
  if (eff.length > 1)
@@ -460,6 +472,10 @@ export class EngineImpl {
460
472
  const ct = node.properties?.countersignType;
461
473
  const now = new Date();
462
474
  const form = node.properties?.form ?? '';
475
+ // issues/126 案 A:与 createTask 同一把尺子。本函数当前**零调用者**(issues/121 P2 把回退改成血缘版后
476
+ // 就没人调它了),按 §1.9 第 1 条口径"接线但不为它造测试"——接线是为了将来复活时不再漏。
477
+ const expireExpr = node.properties?.expireTime;
478
+ const expireArgs = inst.variables;
463
479
  if (isCountersign(node.properties?.performType) && ct) {
464
480
  switch (ct) {
465
481
  case 'PARALLEL':
@@ -469,6 +485,7 @@ export class EngineImpl {
469
485
  const eff = mergeAgents([actor], agents);
470
486
  if (eff.length > 1)
471
487
  nt.actorIds = eff;
488
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
472
489
  await this.repo.saveTask(nt);
473
490
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
474
491
  }
@@ -483,6 +500,7 @@ export class EngineImpl {
483
500
  const eff = mergeAgents([actors[0]], agents);
484
501
  if (eff.length > 1)
485
502
  nt.actorIds = eff;
503
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
486
504
  await this.repo.saveTask(nt);
487
505
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
488
506
  return;
@@ -493,6 +511,7 @@ export class EngineImpl {
493
511
  const eff = mergeAgents([actor], agents);
494
512
  if (eff.length > 1)
495
513
  nt.actorIds = eff;
514
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
496
515
  await this.repo.saveTask(nt);
497
516
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
498
517
  }
@@ -503,6 +522,7 @@ export class EngineImpl {
503
522
  const nt = inst.createTask(this.nextId(), node.id, node.text.value, effActors[0], operator, form, now, parentId, isFirst);
504
523
  if (effActors.length > 1)
505
524
  nt.actorIds = effActors;
525
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
506
526
  await this.repo.saveTask(nt);
507
527
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
508
528
  }
@@ -631,6 +651,10 @@ export class EngineImpl {
631
651
  const ct = node.properties?.countersignType;
632
652
  const now = new Date();
633
653
  const form = node.properties?.form ?? '';
654
+ // issues/126 案 A:节点到期表达式(properties.expireTime)+ 实例变量 + 本函数取时基准 now
655
+ // —— 三处写点(串行首位 / 并行全员 / 普通建单)共用 applyNodeExpireTime 这一把尺子
656
+ const expireExpr = node.properties?.expireTime;
657
+ const expireArgs = inst.variables;
634
658
  if (isCountersign(node.properties?.performType) && ct) {
635
659
  switch (ct) {
636
660
  case 'PARALLEL':
@@ -639,6 +663,7 @@ export class EngineImpl {
639
663
  const eff = mergeAgents([actor], agents);
640
664
  if (eff.length > 1)
641
665
  nt.actorIds = eff;
666
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 并行会签全员
642
667
  await this.repo.saveTask(nt);
643
668
  // TASK_CREATE:任务落库后逐个 fire(会签多任务逐个,对齐 Java CreateTaskHandler)
644
669
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
@@ -656,6 +681,7 @@ export class EngineImpl {
656
681
  const eff = mergeAgents([actors[0]], agents);
657
682
  if (eff.length > 1)
658
683
  nt.actorIds = eff;
684
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 串行会签首位成员
659
685
  await this.repo.saveTask(nt);
660
686
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
661
687
  return;
@@ -666,6 +692,7 @@ export class EngineImpl {
666
692
  const eff = mergeAgents([actor], agents);
667
693
  if (eff.length > 1)
668
694
  nt.actorIds = eff;
695
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 未配会签类型=全员预创建,与并行同档
669
696
  await this.repo.saveTask(nt);
670
697
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
671
698
  }
@@ -677,6 +704,7 @@ export class EngineImpl {
677
704
  const nt = inst.createTask(this.nextId(), node.id, node.text.value, effActors[0], operator, form, now, parentId, isFirst);
678
705
  if (effActors.length > 1)
679
706
  nt.actorIds = effActors;
707
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 普通建单
680
708
  await this.repo.saveTask(nt);
681
709
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
682
710
  }
@@ -875,3 +903,99 @@ function filterFieldByPerm(args, node) {
875
903
  }
876
904
  return out;
877
905
  }
906
+ // ─── issues/126 案 A · 任务行到期时间(expire_time)求值与写入 ────────────────────
907
+ /** 绝对时刻格式 "yyyy-MM-dd HH:mm:ss"(Java SimpleDateFormat / C# TimeFormat 同串) */
908
+ const ABS_TIME_RE = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
909
+ /** 按 "yyyy-MM-dd HH:mm:ss" 严格解析(本地时区);不合规/越界一律 null。
910
+ * 越界判据取 C# 的 TryParseExact(拒 13 月 / 25 时),不取 Java 的 SimpleDateFormat 宽松进位——
911
+ * 本案的硬要求是"解析不出 ⇒ 这一列留空",宽松进位会把误配的值算成一个真时刻。 */
912
+ function parseAbsTime(s) {
913
+ const m = ABS_TIME_RE.exec(s);
914
+ if (!m)
915
+ return null;
916
+ const [, ys, mos, ds, hs, mis, ss] = m;
917
+ const mo = Number(mos), d = Number(ds), h = Number(hs), mi = Number(mis), sec = Number(ss);
918
+ if (mo < 1 || mo > 12 || d < 1 || d > 31 || h > 23 || mi > 59 || sec > 59)
919
+ return null;
920
+ const dt = new Date(Number(ys), mo - 1, d, h, mi, sec, 0);
921
+ // 2 月 30 日这类"字段合法但日历上不存在"的值会被 JS 进位,回读校验挡掉
922
+ if (dt.getMonth() !== mo - 1 || dt.getDate() !== d)
923
+ return null;
924
+ return dt;
925
+ }
926
+ /** 相对档前缀取整:必须是**纯整数**且落在 int32 内(C# int.TryParse 同判据),否则返回 null ⇒ 落穿。
927
+ * 与 Java 的差异是故意的:Java 的 Integer.parseInt 遇 "xh" 会抛异常**打断建单**,
928
+ * owner 2026-09-28 定的口径是按 C# 落穿→NULL(配置写错不该让流程卡死);要改回"跟 Java 一样抛"必须八栈同批改。 */
929
+ function intPrefix(s) {
930
+ if (!/^[-+]?\d+$/.test(s))
931
+ return null;
932
+ const n = Number(s);
933
+ return Number.isSafeInteger(n) && Math.abs(n) <= 2147483647 ? n : null;
934
+ }
935
+ /**
936
+ * 解析期待完成时间(逐字移植 Java `FlowUtil.processTime` / C# `FlowUtil.ProcessTime`,本栈原先没有)。
937
+ *
938
+ * 三档语义,**顺序不能变**:
939
+ * 1. `args` 里存在键名等于 expr 原串的项 ⇒ 取该项的值:Date / 毫秒时间戳 / `"yyyy-MM-dd HH:mm:ss"`
940
+ * → 该时刻;字符串解析失败 → **null**(不是 now);其它类型(布尔/数组/对象/小数)→ **落穿**到下面两档
941
+ * (Java/C# 都是落穿,不许当"解析失败"提前 return null)。
942
+ * 2. 否则 expr 以 `s`/`m`/`h`/`d` 结尾且前缀是整数 ⇒ now + N 秒/分/时/天(`d` 走**日历加天**,不乘 86400 秒)。
943
+ * 3. 否则把 expr 本身按 `"yyyy-MM-dd HH:mm:ss"` 解析 → 时刻;失败 → null。
944
+ *
945
+ * ⚠️ 任何一档都不得退回 now()——"算不出来就写当前时间"正是 issues/126 的病灶(建单即逾期,逾期统计恒失真)。
946
+ *
947
+ * @param now 取时基准=**本栈写 createTime 用的同一个 Date**(本栈无时钟槽,与 Java 直接用系统钟同档)
948
+ */
949
+ export function processTime(expr, args, now) {
950
+ const a = args ?? {};
951
+ // ① 变量档:优先于相对档(args 里真有个键叫 "2h" 时取变量值)
952
+ if (Object.prototype.hasOwnProperty.call(a, expr)) {
953
+ const v = a[expr];
954
+ if (v instanceof Date)
955
+ return new Date(v.getTime());
956
+ if (typeof v === 'number' && Number.isSafeInteger(v))
957
+ return new Date(v);
958
+ if (typeof v === 'string')
959
+ return parseAbsTime(v);
960
+ // 其它类型 ⇒ 落穿
961
+ }
962
+ if (expr.trim() === '')
963
+ return null;
964
+ // ② 相对档
965
+ const n = intPrefix(expr.slice(0, -1));
966
+ if (n !== null) {
967
+ switch (expr.charAt(expr.length - 1)) {
968
+ case 's': return new Date(now.getTime() + n * 1000);
969
+ case 'm': return new Date(now.getTime() + n * 60000);
970
+ case 'h': return new Date(now.getTime() + n * 3600000);
971
+ case 'd': {
972
+ const d = new Date(now.getTime());
973
+ d.setDate(d.getDate() + n); // 日历加天(跨夏令时/月末按天进位,对齐 Java Calendar.add)
974
+ return d;
975
+ }
976
+ default: break;
977
+ }
978
+ }
979
+ // ③ 绝对档
980
+ return parseAbsTime(expr);
981
+ }
982
+ /**
983
+ * issues/126 案 A · 任务行 expire_time 的**唯一**写入口(五处写点共用同一把尺子):
984
+ * 普通建单 / 串行会签首位成员 / 并行会签全员 / 回退新建 / 串行会签推进出的下一位成员。
985
+ *
986
+ * 节点没配(undefined / null / 空串 / 纯空白)⇒ **该列保持空**:不写 now()、不写 ''、不写 0
987
+ * (owner 2026-09-28 口径,对齐 boot2 `if(StrUtil.isNotEmpty(expireTime))` 的先判再写)。
988
+ *
989
+ * 变量源两档:建单路径=**实例变量**(boot2 的 `execution.getArgs()`),
990
+ * 回退新建=**随行拷贝那份变量**(boot2 的 `hisVariable`)。搞混会让"表达式是个变量名"这一档跨栈得到不同答案。
991
+ */
992
+ function applyNodeExpireTime(task, expr, args, now) {
993
+ if (!task)
994
+ return;
995
+ const s = expr == null ? '' : String(expr);
996
+ if (s.trim() === '')
997
+ return;
998
+ const at = processTime(s, args, now);
999
+ if (at)
1000
+ task.expireTime = at;
1001
+ }
package/dist/facade.js CHANGED
@@ -281,6 +281,11 @@ export class JeeflowFacade {
281
281
  const isActor = withdrawn.some(t => (t.actorIds ?? []).includes(operator));
282
282
  if (!isSystem && !isStarter && !isActor)
283
283
  throw new Error('无权限撤回该流程实例');
284
+ // issues/53 E25:撤回状态应为 Withdraw(30) 而非 Reject(45)(对齐 Java)
285
+ // issues/134 案 A:实例状态守卫在聚合根 withdraw 内(state≠10 ⇒ 抛 20010009 固定文案),
286
+ // 故排在任务行改写**之前**——被拒时任务行与实例一行都不动,下方两次落库也走不到。
287
+ inst.withdraw(now);
288
+ inst.updateUser = operator;
284
289
  for (const t of withdrawn) {
285
290
  // issues/113:撤回写 Withdraw(30),不用 Abandoned(99)——99 是引擎废弃码
286
291
  // (会签一票否决 / abandonAllDoing 用它),混用会让撤回单与废弃单在任务表里塌成同值
@@ -288,9 +293,6 @@ export class JeeflowFacade {
288
293
  // issues/114:进行中任务的 update_user 同样回写为撤回人(与实例口径一致)
289
294
  t.updateUser = operator;
290
295
  }
291
- // issues/53 E25:撤回状态应为 Withdraw(30) 而非 Reject(45)(对齐 Java)
292
- inst.withdraw(now);
293
- inst.updateUser = operator;
294
296
  // 级联覆盖防护(issues/57 补正):撤回副本同步回聚合——updateInstance 级联会用
295
297
  // 聚合内旧任务覆盖已撤回状态(memory 加载 tasks 时必现);已完成(20)/已终止(40)
296
298
  // 任务行不在 withdrawn 内,天然不被改写
@@ -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.32",
3
+ "version": "1.8.34",
4
4
  "description": "jeeflow workflow engine — Node.js / TypeScript implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",