@mldong/jeeflow 1.8.34 → 1.8.36

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/spi.js CHANGED
@@ -23,3 +23,142 @@ export function isBlankValue(val) {
23
23
  export function isBlankOwnership(column, operator, val) {
24
24
  return OWNERSHIP_COLUMNS.has(column) && operator.toUpperCase() === 'EQ' && isBlankValue(val);
25
25
  }
26
+ /**
27
+ * 归属证据的**有效性**判据(issues/141 G1 · 逐字对齐 java
28
+ * `JdbcProcessRepository#hasEffectiveCondition` 的反面):在 `isBlankValue` 的三形
29
+ * (null / undefined / 全空白串)之上再收一档**空集合**——`[]` 表达的是「谁都没有」,
30
+ * 与空串同档。这一档不补上,同一份数据在两仓会各说各话:内存仓 `[].trim()` 直接 TypeError,
31
+ * SQL 仓把数组当标量绑进 `cc.actor_id = ?` 下库(既不是空页也不是报错口径统一)。
32
+ */
33
+ export function isBlankOwnershipValue(val) {
34
+ if (isBlankValue(val))
35
+ return true;
36
+ return Array.isArray(val) && val.length === 0;
37
+ }
38
+ /** 抄送归属列(`pageCcInstances` 的归属证据落在这一列上,与 OWNERSHIP_COLUMNS 里那枚同名)。 */
39
+ const CC_OWNERSHIP_COLUMN = 'cc.actor_id';
40
+ /**
41
+ * 抄送分页的**归属条件必填**判据(issues/141 G1 · spec 06 §2.5「抄送分页同一条尺子」)。
42
+ *
43
+ * 本栈的归属证据有两路:门面下发的**位置参** `actorId`(java 下发的是 `cc.actor_id EQ` 条件,
44
+ * 形状不同、义务相同)与 `conditions` 里打在 `cc.actor_id` 上的条件。判据:
45
+ * ① 位置参无效(缺 / 空串 / 全空白 / null / 空集合)⇒ **空页**;
46
+ * ② `conditions` 里凡是打在 `cc.actor_id` 上的条件,只要有一条值无效 ⇒ **空页**
47
+ * (含 java 那格「空 IN ⇒ 空页」;这一路不看 operator,与 java `hasEffectiveCondition` 一致);
48
+ * ③ 非归属列(`m_LIKE_businessNo` 等**可选过滤**)的空值放行**不变**,仍按「没填」忽略——
49
+ * 本判据只看 `cc.actor_id`,绝不把可选过滤一起改成空页。
50
+ *
51
+ * ⚠️ 两仓(`JdbcRepository` / `MemoryRepository`)**共用这一份实现**,不是各写一遍:
52
+ * 「同一栈两个仓储两个答案」正是 issues/117 场景 27 立过法的形状,判据只留一处才不可能分叉。
53
+ */
54
+ export function hasEffectiveCcOwnership(actorId, conditions) {
55
+ if (isBlankOwnershipValue(actorId))
56
+ return false;
57
+ for (const c of conditions ?? []) {
58
+ if (c.column !== CC_OWNERSHIP_COLUMN)
59
+ continue;
60
+ if (isBlankOwnershipValue(c.value))
61
+ return false;
62
+ }
63
+ return true;
64
+ }
65
+ /**
66
+ * 归属值**单个**入参的归一值(issues/141 G10 spec 06 §2.10 + issues/142 B 批 §2.11 共用的
67
+ * **那一枚**判据):`null`/`undefined` ⇒ 空串(即"没有归属人");其余取 `String(val).trim()`。
68
+ *
69
+ * ⚠️ 落库与比较一律用这个返回值,`" 123 "` 与 `"123"` 是同一个人——不 trim 就会与 §4 的
70
+ * 写侧判重错开、同一人落两行。反向哨兵:判据只吃空值,`"0"` 这类"看起来像空"的正常 id
71
+ * 归一后是 `"0"`,**不得**被丢掉。
72
+ *
73
+ * ⚠️ 判空一律 `String(x).trim() === ''`(即"本函数返回空串"),**严禁** `.filter(Boolean)`/
74
+ * `if (!x)` 这类语言自带假值判据——它们会吃掉 `'0'`(spec 06 §2.11 硬要求④,php 本轮实测
75
+ * 无回调 `array_filter` 同款)。
76
+ */
77
+ export function normalizeActorValue(val) {
78
+ if (val == null)
79
+ return '';
80
+ return String(val).trim();
81
+ }
82
+ /**
83
+ * 归属值**集合**归一(issues/141 G10「空不创建行」spec 06 §2.10 + issues/142 B 批 §2.11
84
+ * 「归属值写侧归一」共用的**那一枚**判据,对齐 java `StringUtils.normalizeCcActors`):
85
+ * 逐元素 {@link normalizeActorValue},**空串 / 纯空白 / null / undefined 一律丢弃**,
86
+ * 同一次调用内的重复折叠,顺序保持。
87
+ *
88
+ * <p>丢完为空时调用方的义务分两档(§2.10 要求③ + §2.11 硬要求③,两档都**不新造错误码/文案**):
89
+ * ① 归属值档(抄送人/加签人):为空 ⇒ 不建行、不 fire 码 4,手动腿与"空集合"既有档同判
90
+ * (本栈既有文案 `'actorIds 缺失'`);
91
+ * ② 主键档(`processTaskId`):**必须响亮报错**——归属值可有可无,主键没有就是调用方写错了,
92
+ * 静默接受会把脏数据钉进表里(本栈既有信封由 `toId()` 出 `'id 缺失或非法'`)。
93
+ *
94
+ * ⚠️ **单点判据**(本仓 G1 的先例:判据函数放 spi.ts,两仓共用,见 `isBlankOwnershipValue`/
95
+ * `hasEffectiveCcOwnership`):
96
+ * cc 侧——漏斗层(`engine.parseCcActors` + 门面手动腿)+ 写侧层(两仓 `createCcInstance` +
97
+ * {@link defaultCreateCcInstanceIfAbsent});
98
+ * 任务侧(§2.11)——漏斗层(门面 `taskAddActor` 的 addCandidate/surrogate 两 action、`transfer`
99
+ * 的 fromActor/toActor、`f_`/`tf_nextNodeOperator` 两腿)+ 写侧层(两仓 `addTaskActor` 与
100
+ * `insertTaskActors`/`saveTask`/`updateTask` 的参与者落库腿、两仓 `updateCcStatus`)。
101
+ * 全部走这一份实现,**严禁各抄一遍**:只修漏斗,绕过门面/引擎直连仓储的调用方照样能把空归属值
102
+ * 灌进 `wf_process_task_actor.actor_id`/`wf_process_cc_instance.actor_id`,那正是 issues/129
103
+ * 那族"空 operator 读全库"的病根;两份判据迟早分叉(php 本轮实测"归一函数内部严格比较、
104
+ * 仓储写侧却用松散 in_array ⇒ `'0' == '00'` 静默丢掉第二个人")。
105
+ *
106
+ * 逗号串与数组两种形态在本函数之上由 `engine.parseActorIds`(`parseCcActors` 是它的别名)收敛成
107
+ * 同一个数组再进来,两形同判据(spec §2.10/§2.11「别只修一条腿」)。
108
+ *
109
+ * @param raw 归属值数组(rest 参数产物 / 已按逗号切开的元素集);非数组按"没有归属人"处理
110
+ */
111
+ export function normalizeActors(raw) {
112
+ const out = [];
113
+ if (!Array.isArray(raw))
114
+ return out;
115
+ const seen = new Set();
116
+ for (const item of raw) {
117
+ const actor = normalizeActorValue(item);
118
+ // 判空只认 trim 后的空串(`'0'` 是正常 id,不是空值);Set 用 SameValueZero,
119
+ // 不会像松散比较那样把 `'0'` 与 `'00'` 折成一个人
120
+ if (actor === '' || seen.has(actor))
121
+ continue;
122
+ seen.add(actor);
123
+ out.push(actor);
124
+ }
125
+ return out;
126
+ }
127
+ /**
128
+ * issues/141 G10 的旧名(当时只有 cc 一支用)。issues/142 B 批按 §2.11 尾注的要求把它**升为通用**
129
+ * 判据(任务侧 addCandidate/surrogate/transfer/nextNodeOperator/写侧两仓共用同一枚),
130
+ * 改名会破 `@mldong/jeeflow/spi` 的既有导出面 ⇒ 采用"新增通用名 + 旧名转发":
131
+ * 下面两枚**就是**上面那两枚(同一个函数对象、不是第二份实现),cc 支继续走同一枚。
132
+ */
133
+ export const normalizeCcActorValue = normalizeActorValue;
134
+ /** 同 {@link normalizeCcActorValue}:{@link normalizeActors} 的旧名转发,不是第二份判据。 */
135
+ export const normalizeCcActors = normalizeActors;
136
+ /**
137
+ * issues/141 G2 —— java `IProcessRepository#createCcInstanceIfAbsent` 那条 `default` 在 TS 里的对应物
138
+ * (接口给不出默认实现,所以做成自由函数,两仓与引擎共用同一份判重逻辑)。
139
+ *
140
+ * 只依赖 `createCcInstance` + 可选的 `findCcActorIds`,**不调用** `createCcInstanceIfAbsent`,
141
+ * 所以自带实现的仓储可以直接 `return defaultCreateCcInstanceIfAbsent(this, …)` 而不会自我递归。
142
+ *
143
+ * 行为:读该实例既有 cc 行 ⇒ 折掉已存在的人与本次入参内的重复 ⇒ 只插新人 ⇒ 返回**实际新建**的子集。
144
+ * 仓储未实现 `findCcActorIds` 时既有集合视作空 ⇒ 与旧 `createCcInstance` 全量插入逐字一致
145
+ * (java 的 default 同理,第三方仓储不被静默改变行为)。
146
+ *
147
+ * <p>issues/141 G10「空不创建行」(spec 06 §2.10):入参先过 {@link normalizeCcActors}——
148
+ * 空串/纯空白/null 丢弃、值取 trim 后的串,所以**返回的子集里没有空值**(子集是拿去 fire 码 4 的
149
+ * 那一份),全空入参 ⇒ `fresh` 为空 ⇒ 连 `createCcInstance` 都不调用。本函数是 java 那条 `default`
150
+ * 的对应物,也是"写侧兜底"这一层:漏斗修好了、绕过引擎直连仓储的调用方仍在这里被同一判据挡住。
151
+ */
152
+ export async function defaultCreateCcInstanceIfAbsent(repo, instanceId, creator, actorIds) {
153
+ const existing = repo.findCcActorIds ? await repo.findCcActorIds(instanceId) : [];
154
+ // issues/141 G10:先归一(空值丢弃+trim+同次折叠),再与既有行判重——与 G2 同一条尺子
155
+ const fresh = [];
156
+ for (const actorId of normalizeCcActors(actorIds)) {
157
+ if (existing.includes(actorId) || fresh.includes(actorId))
158
+ continue;
159
+ fresh.push(actorId);
160
+ }
161
+ if (fresh.length > 0)
162
+ await repo.createCcInstance(instanceId, creator, ...fresh);
163
+ return fresh;
164
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mldong/jeeflow",
3
- "version": "1.8.34",
3
+ "version": "1.8.36",
4
4
  "description": "jeeflow workflow engine — Node.js / TypeScript implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",