@mldong/jeeflow 1.8.33 → 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/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.33",
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",